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

            Bug ID: 79604
           Summary: attribute noreturn inconsistent between C and C++,
                    undocumented for function pointers
           Product: gcc
           Version: 7.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: ---

Like GCC (in C mode) G++ accepts attribute noreturn on function pointer
declarations, but unlike in C mode then ignores the attribute when the pointer
is used to call a function.  G++ should be consistent with GCC.

In addition, the effects of the attribute on function pointers are not
documented in the Common Variable Attributes section of the manual.  The
attribute should be mentioned there as well and its effects on function
pointers should be documented.

$ (set -x && cat u.C && for lang in c c++; do gcc -S -Wall -Wunused -Wpedantic
-x$lang u.C; done)
+ cat u.C
void (*pf)() __attribute__ ((noreturn));

void (*pg)();

int foo ()
{
  pf ();   // no warning in C (good), but warning in C++ (bug)
}

int bar ()
{
  pg ();   // warning in both C and C++ (good)
}
+ for lang in c c++
+ /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -S -Wall -Wunused -Wpedantic
-xc u.C
u.C: In function ‘bar’:
u.C:13:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
+ for lang in c c++
+ /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -S -Wall -Wunused -Wpedantic
-xc++ u.C
u.C: In function ‘int foo()’:
u.C:8:1: warning: no return statement in function returning non-void
[-Wreturn-type]
 }
 ^
u.C: In function ‘int bar()’:
u.C:13:1: warning: no return statement in function returning non-void
[-Wreturn-type]
 }
 ^

Reply via email to