From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4651A385780E; Fri, 7 Jan 2022 23:47:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4651A385780E From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/57632] Operator new overloads with stdc++11 enabled looses exception specifier (MacOsX) Date: Fri, 07 Jan 2022 23:47:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.2 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jan 2022 23:47:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D57632 --- Comment #6 from Andrew Pinski --- (In reply to Jonathan Wakely from comment #5) > I agree with comment 3 that the current diagnostic is poor: Oh I missed that. >=20 > #include > void* operator new(std::size_t mem) throw(std::bad_alloc); > void* operator new(std::size_t mem) throw(std::bad_alloc); >=20 >=20 > g++ -std=3Dc++11 -c new.cc -Wno-deprecated > new.cc:3:7: error: declaration of =E2=80=98void* operator new(std::size_t= ) throw > (std::bad_alloc)=E2=80=99 has a different exception specifier > 3 | void* operator new(std::size_t mem) throw(std::bad_alloc); > | ^~~~~~~~ > new.cc:2:7: note: from previous declaration =E2=80=98void* operator new(s= td::size_t)=E2=80=99 > 2 | void* operator new(std::size_t mem) throw(std::bad_alloc); > | ^~~~~~~~ >=20 Reduced testcase for that: void f(void); void f(void) throw(int); void f(void) throw(int); Noexcept has the same issue: void g(void); void g(void) noexcept; void g(void) noexcept; I suspect what happens is the following when we merge the two decls we chose the new decl for the location but we remove the exception specifier/noexcept (confirmed by swapping the first two decls and seeing the error again).=