[gcc r17-3023] testsuite: Add yet another [[clang::no_specializations]] testcase [PR120635]

Jakub Jelinek via Gcc-cvs <[email protected]> Thu, 6 Aug 2026 09:56:48 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:1a9d7ee08ed49c637e94dad2695532d78909f24f

commit r17-3023-g1a9d7ee08ed49c637e94dad2695532d78909f24f
Author: Jakub Jelinek <[email protected]>
Date:   Thu Aug 6 11:56:08 2026 +0200

    testsuite: Add yet another [[clang::no_specializations]] testcase [PR120635]
    
    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.
    
    2026-08-06  Jakub Jelinek  <[email protected]>
    
            PR c++/120635
            * g++.dg/ext/attr-no_specializations13.C: New test.
    
    Reviewed-by: Jason Merrill <[email protected]>

Diff:
---
 .../g++.dg/ext/attr-no_specializations13.C         | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/gcc/testsuite/g++.dg/ext/attr-no_specializations13.C b/gcc/testsuite/g++.dg/ext/attr-no_specializations13.C
new file mode 100644
index 000000000000..57c35ed54f00
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-no_specializations13.C
@@ -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" }