public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-11087] c++: constinit on pointer to function [PR104066]
@ 2022-11-18 0:47 Marek Polacek
0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2022-11-18 0:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b9b78b4de3c7dcc6868c4af831b2d213fda21b04
commit r10-11087-gb9b78b4de3c7dcc6868c4af831b2d213fda21b04
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Nov 17 11:59:29 2022 -0500
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.c (grokdeclarator): Check funcdecl_p before complaining
about constinit.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constinit18.C: New test.
(cherry picked from commit 7b3b2f50953c5143d4b14b59d322d8a793f411dd)
Diff:
---
gcc/cp/decl.c | 2 +-
gcc/testsuite/g++.dg/cpp2a/constinit18.C | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 38003a5a70f..6af7a97a7b9 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12275,7 +12275,7 @@ grokdeclarator (const cp_declarator *declarator,
"an array", name);
return error_mark_node;
}
- if (constinit_p)
+ if (constinit_p && funcdecl_p)
{
error_at (declspecs->locations[ds_constinit],
"%<constinit%> on function return type is not "
diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit18.C b/gcc/testsuite/g++.dg/cpp2a/constinit18.C
new file mode 100644
index 00000000000..51b4f0273be
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/constinit18.C
@@ -0,0 +1,12 @@
+// PR c++/104066
+// { dg-do compile { target c++20 } }
+
+constinit void (*p)() = nullptr;
+constinit void (*pp)() = nullptr;
+void fn();
+constinit void (&r)() = fn;
+
+extern constinit long (* const syscall_reexported) (long, ...);
+
+constinit void bad (); // { dg-error ".constinit. on function return type is not allowed" }
+constinit void bad () { } // { dg-error ".constinit. on function return type is not allowed" }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-18 0:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 0:47 [gcc r10-11087] c++: constinit on pointer to function [PR104066] Marek Polacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).