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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|9.0                         |10.0, 9.2.0
   Last reconfirmed|2018-09-14 00:00:00         |2020-3-16

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
No change in GCC 10.

Specifying the attribute on function pointers is useful so I'd say the fact
that it's not permitted is yet another example of the poor specification of
attributes in C++.  At the same time, assigning the address of a function not
declared noreturn to a noreturn function pointer is a bug that should be
diagnosed.

G++ does report a warning when the C++-style attribute follow the return type
of the function.

Here's an expanded test case showing the difference, plus the GNU form of the
attribute for contrast.

$ cat pr80495.C && gcc -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout pr80495.C
void f (void) { }

[[noreturn]] void (*p1)(void) = f;   // no warning, attribute applied
void [[noreturn]] (*p2)(void) = f;   // warning, attribute ignored

__attribute__ ((noreturn)) void (*q1)(void) = f;  // missing warning
void __attribute__ ((noreturn)) (*q2)(void) = f;  // missing warning

void g1 (int *a)
{
  p1 ();
  *a = 0;   // eliminated
}

void g2 (int *a)
{
  p2 ();
  *a = 1;   // not eliminated
}

void h1 (int *a)
{
  q1 ();
  *a = 2;   // eliminated
}

void h2 (int *a)
{
  q2 ();
  *a = 3;   // eliminated
}

pr80495.C:4:6: warning: attribute ignored [-Wattributes]
    4 | void [[noreturn]] (*p2)(void) = f;   // warning, attribute ignored
      |      ^
pr80495.C:4:6: note: an attribute that appertains to a type-specifier is
ignored

;; Function f (_Z1fv, funcdef_no=0, decl_uid=2327, cgraph_uid=1,
symbol_order=0)

f ()
{
  <bb 2> [local count: 1073741824]:
  return;

}



;; Function g1 (_Z2g1Pi, funcdef_no=1, decl_uid=2334, cgraph_uid=2,
symbol_order=5) (executed once)

g1 (int * a)
{
  void (*<T33d>) (void) p1.0_1;

  <bb 2> [local count: 1073741824]:
  p1.0_1 = p1;
  p1.0_1 ();

}



;; Function g2 (_Z2g2Pi, funcdef_no=2, decl_uid=2337, cgraph_uid=3,
symbol_order=6)

g2 (int * a)
{
  void (*<T33b>) (void) p2.1_1;

  <bb 2> [local count: 1073741824]:
  p2.1_1 = p2;
  p2.1_1 ();
  *a_4(D) = 1;
  return;

}



;; Function h1 (_Z2h1Pi, funcdef_no=3, decl_uid=2340, cgraph_uid=4,
symbol_order=7) (executed once)

h1 (int * a)
{
  void (*<T33d>) (void) q1.2_1;

  <bb 2> [local count: 1073741824]:
  q1.2_1 = q1;
  q1.2_1 ();

}



;; Function h2 (_Z2h2Pi, funcdef_no=4, decl_uid=2343, cgraph_uid=5,
symbol_order=8) (executed once)

h2 (int * a)
{
  void (*<T33d>) (void) q2.3_1;

  <bb 2> [local count: 1073741824]:
  q2.3_1 = q2;
  q2.3_1 ();

}

Reply via email to