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

            Bug ID: 99974
           Summary: attributes not propagated across function
                    redeclarations at local scope
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The C++ front end fails to merge the noreturn and warn_unused_result function
attributes from one declaration at function scope to another.  This is unlike
the C front end which merges some but not others (see pr99972).

$ cat z.C && gcc -S -Wall z.C
int gnr ()
{ 
  extern __attribute__ ((noreturn)) int fnr ();
  fnr ();
}  // no return, no warning (good)

int hnr ()
{
  extern int fnr ();

  fnr ();
}  // bogus -Wreturn-type (bug)


void gwur ()
{
  extern __attribute__ ((warn_unused_result)) int fwur ();
  fwur ();   // -Wunused-result (good)
}

void hwur ()
{
  extern int fwur (); 

  fwur ();   // missing -Wunused-result (bug)
}
z.C: In function ‘int hnr()’:
z.C:12:1: warning: no return statement in function returning non-void
[-Wreturn-type]
   12 | }  // bogus -Wreturn-type (bug)
      | ^
z.C: In function ‘void gwur()’:
z.C:18:8: warning: ignoring return value of ‘int fwur()’ declared with
attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   fwur ();   // -Wunused-result (good)
      |   ~~~~~^~

Reply via email to