xref: /llvm-project/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp (revision a1bce0b89e800cb7ab1d3cf3437f8f34d0695468)
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,spec %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-explicit-specialization-storage-class %s
3 
4 // A storage-class-specifier shall not be specified in an explicit
5 // specialization (14.7.3) or an explicit instantiation (14.7.2)
6 // directive.
f(T)7 template<typename T> void f(T) {}
g(T)8 template<typename T> static void g(T) {}
9 
10 
11 template<> static void f<int>(int); // spec-warning{{explicit specialization cannot have a storage class}}
12 template static void f<float>(float); // expected-error{{explicit instantiation cannot have a storage class}}
13 
14 template<> void f<double>(double);
15 template void f<long>(long);
16 
17 template<> static void g<int>(int); // spec-warning{{explicit specialization cannot have a storage class}}
18 template static void g<float>(float); // expected-error{{explicit instantiation cannot have a storage class}}
19 
20 template<> void g<double>(double);
21 template void g<long>(long);
22 
23 template<typename T>
24 struct X {
25   static int value;
26 };
27 
28 template<typename T>
29 int X<T>::value = 17;
30 
31 template static int X<int>::value; // expected-error{{explicit instantiation cannot have a storage class}}
32 
33 template<> static int X<float>::value; // spec-warning{{explicit specialization cannot have a storage class}}
34                                        // expected-error@-1{{'static' can only be specified inside the class definition}}
35 
36 struct t1 {
37   template<typename>
38   static void f1();
39   template<>
40   static void f1<int>(); // spec-warning{{explicit specialization cannot have a storage class}}
41 };
42