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

            Bug ID: 90895
           Summary: __attribute__((warning(""))) doesn't work for
                    dynamically dispatched calls to virtual functions
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

struct Base
{
   __attribute__((warning("called f"))) void f() { }
   __attribute__((warning("called g"))) virtual void g() { }
};

void f(Base& b)
{
  b.f(); // warns
  b.g();

  Base b2;
  b2.g(); // warns
}


warn.cc: In function 'void f(Base&)':
warn.cc:9:6: warning: call to 'Base::f' declared with attribute warning: called
f [-Wattribute-warning]
    9 |   b.f(); // warns
      |   ~~~^~
warn.cc:13:7: warning: call to 'Base::g' declared with attribute warning:
called g [-Wattribute-warning]
   13 |   b2.g(); // warns
      |   ~~~~^~

It seems reasonable for users to expect b.g() to trigger the warning, even
though the call might actually resolve to an overrider in a derived class.

Reply via email to