Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
Annotations on void parameter don't make much sense so they
should be rejected, even if the wording isn't currently so
clear on that.

        PR c++/123618

gcc/cp/ChangeLog:

        * tree.cc (handle_annotation_attribute): Reject annotations on void
        parameters.

gcc/testsuite/ChangeLog:

        * g++.dg/reflect/annotations14.C: New test.
---
 gcc/cp/tree.cc                               | 6 ++++++
 gcc/testsuite/g++.dg/reflect/annotations14.C | 5 +++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/reflect/annotations14.C

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 20288ed04eb..7296f2b5c0d 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -5912,6 +5912,12 @@ handle_annotation_attribute (tree *node, tree ARG_UNUSED 
(name),
       *no_add_attrs = true;
       return NULL_TREE;
     }
+  if (TREE_CODE (*node) == PARM_DECL && VOID_TYPE_P (TREE_TYPE (*node)))
+    {
+      error ("annotation on void parameter");
+      *no_add_attrs = true;
+      return NULL_TREE;
+    }
   if (!type_dependent_expression_p (TREE_VALUE (args)))
     {
       if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
diff --git a/gcc/testsuite/g++.dg/reflect/annotations14.C 
b/gcc/testsuite/g++.dg/reflect/annotations14.C
new file mode 100644
index 00000000000..d22a9fff3ff
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/annotations14.C
@@ -0,0 +1,5 @@
+// PR c++/123618
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+void f([[=1]] void) {}  // { dg-error "annotation on void parameter" }

base-commit: 2894493adf7434a83b9ead2617468e817b337126
-- 
2.53.0

Reply via email to