]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: constinit on pointer to function [PR104066]
authorMarek Polacek <polacek@redhat.com>
Thu, 17 Nov 2022 16:59:29 +0000 (11:59 -0500)
committerMarek Polacek <polacek@redhat.com>
Fri, 18 Nov 2022 00:39:15 +0000 (19:39 -0500)
commit14faa5f585f6025df1e04c8c8b34340ff5e4d494
tree30e82437c31bb970b0ac29df0d6ea254e61be81a
parent61537f7d8611934d9497547aec57e783f0b1f86c
c++: constinit on pointer to function [PR104066]

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

Thus, this ought to be OK:

  constinit void (*p)() = nullptr;

but the error message I introduced when implementing constinit was
not looking at funcdecl_p, so the code above was rejected.

Fixed thus.  I'm checking constinit_p first because I think that's
far more likely to be false than funcdecl_p.

PR c++/104066

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Check funcdecl_p before complaining
about constinit.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constinit18.C: New test.

(cherry picked from commit 7b3b2f50953c5143d4b14b59d322d8a793f411dd)
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp2a/constinit18.C [new file with mode: 0644]