c++: disallow constinit on functions [PR111173]
commitc121afc3b6c96a1f229ba0c4a4de6bd4b6be9a53
authorMarek Polacek <polacek@redhat.com>
Tue, 29 Aug 2023 17:16:41 +0000 (29 13:16 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 30 Aug 2023 14:40:12 +0000 (30 10:40 -0400)
tree9c6b8b14a966eee3c25b75f138217389732602ba
parent7f2ed06ddc825e8a4e0edfd1d66b5156e6dc1d34
c++: disallow constinit on functions [PR111173]

[dcl.constinit]/1: The constinit specifier shall be applied only to a declaration
of a variable with static or thread storage duration.

and while we detect

  constinit int fn();

we weren't detecting

  using F = int();
  constinit F f;

PR c++/111173

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Disallow constinit on functions.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constinit19.C: New test.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp2a/constinit19.C [new file with mode: 0644]