https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117337
Bug ID: 117337 Summary: Wreturn-type false positive on [[noreturn]] override Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: k4lizen at proton dot me Target Milestone: --- Created attachment 59481 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59481&action=edit source file Versions: g++ (GCC) 14.2.1 20240910 6.11.3-artix1-1 I'm trying to use [[noreturn]] on a function being inherited as pure virtual but I keep getting the Wreturn-type warning no matter what I do. Reproduction code: ================== #include <stdexcept> class A { private: [[noreturn]] virtual void will_throw() = 0; }; class B : public A { public: int returnsathing(); private: [[noreturn]] void will_throw() override; }; [[noreturn]] void B::will_throw(){ throw std::runtime_error("i threw"); } int B::returnsathing() { will_throw(); } int main () { B b; b.returnsathing(); return 0; } ================== ~> g++ main.cpp -o ./main -Werror main.cpp: In member function ‘int B::returnsathing()’: main.cpp:21:1: error: no return statement in function returning non-void [-Werror=return-type] 21 | } | ^ cc1plus: all warnings being treated as errors ================== There's this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61379 which is about pure virtual functions not adhering to [[noreturn]] but I can understand that there is some complication there due to the compiler not knowing where the function is going to come from at runtime. Here, returnsathing is getting the warning, but it is defined in B, which has a definition for will_throw() with [[noreturn]] annotated explicitly again. Does [[noreturn]] just not work with inherited/overriden functions at all? If what is happening is intended behaviour (I doubt it?), maybe a warning should be emmited for annotating such functions with [[noreturn]] in the first place? clang++ doesn't emit the return-type warning from what I can tell. Here are some links to related stuff: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61379 https://stackoverflow.com/questions/58882878/g-noreturn-on-a-virtual-method https://stackoverflow.com/questions/32655526/overriding-a-noreturn-virtual-function https://github.com/llvm/llvm-project/issues/12572