Re: [PATCH] testsuite: Add yet another [[clang::no_specializations]] testcase [PR120635]
Jason Merrill <[email protected]> Wed, 5 Aug 2026 19:24:08 -0400
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
On 7/16/26 7:04 AM, Jakub Jelinek wrote: > Hi! > > In the libstdc++ _Clang::no_specializations thread, we've noticed that > the GCC implementation can properly handle attributes on template > declarations followed by primary template definitions without the attribute > and still diagnose later explicit or partial specializations, while > clang++ didn't handle that. clang++ is being fixed, the following patch > adds another testcase to verify we don't regress in that. > > Tested on x86_64-linux, ok for trunk? OK. > 2026-07-16 Jakub Jelinek <[email protected]> > > PR c++/120635 > * g++.dg/ext/attr-no_specializations13.C: New test. > > --- gcc/testsuite/g++.dg/ext/attr-no_specializations13.C.jj 2026-07-16 12:13:57.764783153 +0200 > +++ gcc/testsuite/g++.dg/ext/attr-no_specializations13.C 2026-07-16 12:50:44.296473787 +0200 > @@ -0,0 +1,25 @@ > +// PR c++/120635 > +// { dg-do compile { target c++11 } } > + > +template <typename T, typename U> > +struct [[clang::no_specializations]] A; > +template <typename T, typename U> > +struct A {}; > +template <> > +struct A <int, int> { int a; }; // { dg-error "'struct A<int, int>' cannot be specialized" } > +#if __cpp_variable_templates >= 201304 > +template <typename T> > +struct B { > + template <typename U> > + static int b [[clang::no_specializations]]; > +}; > +template <> > +template <> > +int B<int>::b <long> = 43; // { dg-error "'B<int>::b<long int>' cannot be specialized" "" { target c++14 } } > +#endif > +template <typename T> > +[[clang::no_specializations]] int foo (); > +template <typename T> > +int foo () { return 42; } > +template <> > +int foo <long> () { return 43; } // { dg-error "'int foo\\\(\\\) \\\[with T = long int\\\]' cannot be specialized" } > > Jakub >