From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 717F2385802E; Fri, 7 Jan 2022 12:47:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 717F2385802E From: "redi 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 12:47:12 +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: redi 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: keywords resolution everconfirmed cf_reconfirmed_on bug_status 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 12:47:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D57632 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Resolution|INVALID |--- Ever confirmed|0 |1 Last reconfirmed| |2022-01-07 Status|RESOLVED |NEW --- Comment #5 from Jonathan Wakely --- I agree with comment 3 that the current diagnostic is poor: #include void* operator new(std::size_t mem) throw(std::bad_alloc); void* operator new(std::size_t mem) throw(std::bad_alloc); 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(std= ::size_t)=E2=80=99 2 | void* operator new(std::size_t mem) throw(std::bad_alloc); | ^~~~~~~~ Why does it accept the incorrect exception specification on line 2, but then give an error for an identical one on line 3? Why do we refer to line 2 in = the note and say it's different, when it's not? Paolo's explanation in comment 1 doesn't make the behaviour correct, it just explains why we behave like that. Either both redeclarations should be vali= d or neither should be valid. So I think either we should either: - accept both redeclarations (as Clang does), or - give a diagnostic (maybe a pedwarn) for the first redeclaration because it doesn't match the one in (and the implicit one predefined by the compiler), and fix the diagnostic to refer to the previous declaration in <= new> instead of the one on line 2.=