Re: [PATCH] c++: disallow constinit on functions [PR111173]
On 8/29/23 15:01, Marek Polacek wrote: Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. -- >8 -- [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++/73 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Disallow constinit on functions. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constinit19.C: New test. --- gcc/cp/decl.cc | 3 +++ gcc/testsuite/g++.dg/cpp2a/constinit19.C | 5 + 2 files changed, 8 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constinit19.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index bea0ee92106..a0e8a24efc0 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -14639,6 +14639,9 @@ grokdeclarator (const cp_declarator *declarator, "storage class % invalid for " "function %qs", name); } + else if (constinit_p) + error_at (declspecs->locations[ds_constinit], + "% specifier invalid for function %qs", name); if (virt_specifiers) error ("virt-specifiers in %qs not allowed outside a class " diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit19.C b/gcc/testsuite/g++.dg/cpp2a/constinit19.C new file mode 100644 index 000..5be610a18a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constinit19.C @@ -0,0 +1,5 @@ +// PR c++/73 +// { dg-do compile { target c++20 } } + +using Function = int(); +constinit Function f; // { dg-error ".constinit. specifier invalid for function" } base-commit: fce74ce2535aa3b7648ba82e7e61eb77d0175546
[PATCH] c++: disallow constinit on functions [PR111173]
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- [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++/73 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Disallow constinit on functions. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constinit19.C: New test. --- gcc/cp/decl.cc | 3 +++ gcc/testsuite/g++.dg/cpp2a/constinit19.C | 5 + 2 files changed, 8 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constinit19.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index bea0ee92106..a0e8a24efc0 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -14639,6 +14639,9 @@ grokdeclarator (const cp_declarator *declarator, "storage class % invalid for " "function %qs", name); } + else if (constinit_p) + error_at (declspecs->locations[ds_constinit], + "% specifier invalid for function %qs", name); if (virt_specifiers) error ("virt-specifiers in %qs not allowed outside a class " diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit19.C b/gcc/testsuite/g++.dg/cpp2a/constinit19.C new file mode 100644 index 000..5be610a18a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constinit19.C @@ -0,0 +1,5 @@ +// PR c++/73 +// { dg-do compile { target c++20 } } + +using Function = int(); +constinit Function f; // { dg-error ".constinit. specifier invalid for function" } base-commit: fce74ce2535aa3b7648ba82e7e61eb77d0175546 -- 2.41.0