On Tue, Mar 17, 2026 at 03:57:00PM -0400, Jason Merrill wrote:
> On 3/17/26 12:40 PM, Marek Polacek wrote:
> > Tested reflect/* on x86_64-pc-linux-gnu, ok for trunk?
>
> OK.
Thanks.
> > -- >8 --
> > Modifying the recently added crash22.C test to use a variable template
> > shows that inform_tree_category doesn't say reflection of what we
> > actually got. With this patch we say:
> >
> > • but 'Y<T>' is a variable template
> > crash23.C:6:13:
> > 6 | constexpr T Y{};
> > | ^
> >
> > I couldn't figure out a test for alias templates so I'm not adding
> > that now.
>
> Doesn't DECL_TYPE_TEMPLATE_P work, if you put it after
> DECL_CLASS_TEMPLATE_P?
I'm not finding any testcase where that would actually trigger.
> > PR c++/124493
> >
> > gcc/cp/ChangeLog:
> >
> > * error.cc (inform_tree_category): Handle variable templates.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * g++.dg/reflect/crash23.C: New test.
> > ---
> > gcc/cp/error.cc | 2 ++
> > gcc/testsuite/g++.dg/reflect/crash23.C | 9 +++++++++
> > 2 files changed, 11 insertions(+)
> > create mode 100644 gcc/testsuite/g++.dg/reflect/crash23.C
> >
> > diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
> > index f198a1fe065..b3e66924e31 100644
> > --- a/gcc/cp/error.cc
> > +++ b/gcc/cp/error.cc
> > @@ -4006,6 +4006,8 @@ inform_tree_category (tree t)
> > inform (loc, "but %qE is a function template", t);
> > else if (DECL_CLASS_TEMPLATE_P (t))
> > inform (loc, "but %qE is a class template", t);
> > + else if (variable_template_p (t))
> > + inform (loc, "but %qE is a variable template", t);
> > else if (TREE_CODE (t) == NAMESPACE_DECL)
> > inform (loc, "but %qE is a namespace", t);
> > else if (TREE_CODE (t) == CONST_DECL && !DECL_TEMPLATE_PARM_P (t))
> > diff --git a/gcc/testsuite/g++.dg/reflect/crash23.C
> > b/gcc/testsuite/g++.dg/reflect/crash23.C
> > new file mode 100644
> > index 00000000000..88d71f05935
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/reflect/crash23.C
> > @@ -0,0 +1,9 @@
> > +// PR c++/124493
> > +// { dg-do compile { target c++26 } }
> > +// { dg-additional-options "-freflection" }
> > +
> > +template<typename T>
> > +constexpr T Y{}; // { dg-message "but .Y<T>. is a variable template" }
> > +template<decltype(^^::) R>
> > +constexpr auto f () -> [:R:]<0> { return {}; } // { dg-error "expected
> > a reflection of a type template" }
> > +constexpr auto a = f<^^Y>(); // { dg-error "no matching function" }
> >
> > base-commit: 9d17a04f241e5c54b98456995ed8ce4d19c7db31
>
Marek