https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120300

--- Comment #2 from Lee Killough <leekillough at gmail dot com> ---
 > The problem is Wmissing-noreturn happens after optimizations so if a
function is defined in-class it has an implicit vague linkage and not included.

The problem is more with false -Wmissing-noreturn warnings on out-of-class
definitions. 

For in-class definitions the -Wmissing-noreturn warnings do not happen even if
it's not virtual (including static) or is marked final, which may be the effect
you're talking about.

The -Wmissing-noreturn false negatives for in-class definitions is much less
serious than the false positives for out-of-class definitions.

For out-of-class definitions of virtual functions which may be overriden, there
should not be a missing noreturn warning.

A common pattern is to define virtual base class functions which abort with
error, but which return normally when overriden. They should not be warned
about missing noreturn.

#include <iostream>
#include <cstdlib>

class Base {
  public:
     virtual void method();
};

// virtual method should not get -Wmissing-noreturn warning
void Base::method() {
    std::cerr << "method not implemented\n";
    abort(); 
}

class Derived1 : public Base {
   public:
     void method() override;
};

void Derived1::method() {
 // do stuff normally
}

> $ g++ -c -Wmissing-noreturn test.cc
> test.cc: In member function ‘virtual void Base::method()’:
> test.cc:10:6: warning: function might be candidate for attribute ‘noreturn’ 
> [-Wsuggest-attribute=noreturn]
>    10 | void Base::method() {
>       |      ^~~~

Reply via email to