On Mon, Mar 16, 2026 at 02:52:17PM -0400, Jason Merrill wrote:
> On 3/16/26 10:41 AM, Marek Polacek wrote:
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> OK, but I'm surprised we even build a PARM_DECL for (void). Why does that
> happen?
We have no special code to avoid doing so in grokdeclarator:
if (decl_context == PARM)
{
decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
...
}
grokparms has special code to deal with void parameters but that
doesn't apply for (void). And anyway, grokparms is called after
handle_annotation_attribute.
> > -- >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
>
Marek