275 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s2 3template<typename T>4int x;5 6template<typename T>7static int x<T*>;8 9template<>10static int x<int>; // expected-warning {{explicit specialization cannot have a storage class}}11 12template<typename T>13extern int y;14 15template<typename T>16static int y<T*>;17 18template<>19static int y<int>; // expected-warning {{explicit specialization cannot have a storage class}}20 21template<typename T>22void f();23 24template<>25static void f<int>(); // expected-warning {{explicit specialization cannot have a storage class}}26 27template<typename T>28extern void g();29 30template<>31static void g<int>(); // expected-warning {{explicit specialization cannot have a storage class}}32 33struct A {34 static int x;35 36 static int y;37 38 static void f();39 40 static void g();41};42 43int A::x = 0;44 45static int A::y = 0; // expected-error {{'static' can only be specified inside the class definition}}46 47void A::f() { }48 49static void A::g() { } // expected-error {{'static' can only be specified inside the class definition}}50 51struct B {52 template<typename T>53 static int x;54 55 template<typename T>56 static int y;57 58 template<typename T>59 int z; // expected-error {{non-static data member 'z' cannot be declared as a template}}60 61 template<typename T>62 static int x<T*>;63 64 template<typename T>65 static int y<T*>;66 67 template<typename T>68 int x<T**>; // expected-error {{non-static data member 'x' cannot be declared as a template}}69 70 template<>71 int x<short>;72 73 template<>74 static int x<long>; // expected-warning {{explicit specialization cannot have a storage class}}75 76 template<typename T>77 static void f();78 79 template<typename T>80 static void g();81 82 template<>83 void f<short>();84 85 template<>86 static void f<long>(); // expected-warning {{explicit specialization cannot have a storage class}}87};88 89template<typename T>90int B::x = 0;91 92template<typename T>93static int B::y = 0; // expected-error {{'static' can only be specified inside the class definition}}94 95template<typename T>96int B::x<T*> = 0;97 98template<typename T>99static int B::y<T*> = 0; // expected-error {{'static' can only be specified inside the class definition}}100 101template<typename T>102int B::x<T***>;103 104template<typename T>105static int B::y<T***>; // expected-error {{'static' can only be specified inside the class definition}}106 107template<>108int B::x<unsigned>;109 110template<>111static int B::y<unsigned>; // expected-warning {{explicit specialization cannot have a storage class}}112 // expected-error@-1 {{'static' can only be specified inside the class definition}}113 114template<typename T>115void B::f() { }116 117template<typename T>118static void B::g() { } // expected-error {{'static' can only be specified inside the class definition}}119 120template<>121void B::f<unsigned>();122 123template<>124static void B::g<unsigned>(); // expected-warning {{explicit specialization cannot have a storage class}}125 // expected-error@-1 {{'static' can only be specified inside the class definition}}126 127template<typename T>128struct C {129 static int x;130 131 static int y;132 133 static void f();134 135 static void g();136};137 138template<typename T>139int C<T>::x = 0;140 141template<typename T>142static int C<T>::y = 0; // expected-error {{'static' can only be specified inside the class definition}}143 144template<typename T>145void C<T>::f() { }146 147template<typename T>148static void C<T>::g() { } // expected-warning {{'static' can only be specified inside the class definition}}149 150template<>151int C<int>::x = 0;152 153template<>154static int C<int>::y = 0; // expected-warning {{explicit specialization cannot have a storage class}}155 // expected-error@-1 {{'static' can only be specified inside the class definition}}156 157template<>158void C<int>::f();159 160template<>161static void C<int>::g(); // expected-warning {{explicit specialization cannot have a storage class}}162 // expected-error@-1 {{'static' can only be specified inside the class definition}}163template<typename T>164struct D {165 template<typename U>166 static int x;167 168 template<typename U>169 static int y;170 171 template<typename U>172 int z; // expected-error {{non-static data member 'z' cannot be declared as a template}}173 174 template<typename U>175 static int x<U*>;176 177 template<typename U>178 static int y<U*>;179 180 template<typename U>181 int x<U**>; // expected-error {{non-static data member 'x' cannot be declared as a template}}182 183 template<>184 int x<short>;185 186 template<>187 static int x<long>; // expected-warning {{explicit specialization cannot have a storage class}}188 189 template<typename U>190 static void f();191 192 template<typename U>193 static void g();194 195 template<>196 void f<short>();197 198 template<>199 static void f<long>(); // expected-warning {{explicit specialization cannot have a storage class}}200};201 202template<typename T>203template<typename U>204int D<T>::x = 0;205 206template<typename T>207template<typename U>208static int D<T>::y = 0; // expected-error {{'static' can only be specified inside the class definition}}209 210template<typename T>211template<typename U>212int D<T>::x<U*> = 0;213 214template<typename T>215template<typename U>216static int D<T>::y<U*> = 0; // expected-error {{'static' can only be specified inside the class definition}}217 218template<typename T>219template<typename U>220int D<T>::x<U***>;221 222template<typename T>223template<typename U>224static int D<T>::y<U***>; // expected-error {{'static' can only be specified inside the class definition}}225 226template<>227template<typename U>228int D<int>::x;229 230template<>231template<typename U>232static int D<int>::y; // expected-warning {{explicit specialization cannot have a storage class}}233 // expected-error@-1 {{'static' can only be specified inside the class definition}}234template<>235template<typename U>236int D<int>::x<U****>;237 238template<>239template<typename U>240static int D<int>::y<U****>; // expected-warning {{explicit specialization cannot have a storage class}}241 // expected-error@-1 {{'static' can only be specified inside the class definition}}242template<>243template<>244int D<int>::x<unsigned>;245 246template<>247template<>248static int D<int>::y<unsigned>; // expected-warning {{explicit specialization cannot have a storage class}}249 // expected-error@-1 {{'static' can only be specified inside the class definition}}250 251template<typename T>252template<typename U>253void D<T>::f() { }254 255template<typename T>256template<typename U>257static void D<T>::g() { } // expected-warning {{'static' can only be specified inside the class definition}}258 259template<>260template<typename U>261void D<int>::f();262 263template<>264template<typename U>265static void D<int>::g(); // expected-warning {{explicit specialization cannot have a storage class}}266 // expected-error@-1 {{'static' can only be specified inside the class definition}}267template<>268template<>269void D<int>::f<unsigned>();270 271template<>272template<>273static void D<int>::g<unsigned>(); // expected-warning {{explicit specialization cannot have a storage class}}274 // expected-error@-1 {{'static' can only be specified inside the class definition}}275