xref: /llvm-project/clang/test/CXX/temp/temp.spec/temp.explicit/p4.cpp (revision e4caa48dbb744fb809db1f6f09de2ed9576efcea)
1*e4caa48dSRichard Smith // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
2*e4caa48dSRichard Smith // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3a8b89d26SDouglas Gregor 
4a8b89d26SDouglas Gregor template<typename T> void f0(T); // expected-note{{here}}
5a8b89d26SDouglas Gregor template void f0(int); // expected-error{{explicit instantiation of undefined function template}}
6a8b89d26SDouglas Gregor 
7a8b89d26SDouglas Gregor template<typename T>
8a8b89d26SDouglas Gregor struct X0 {
9d6ba93dcSDouglas Gregor   struct Inner;
10d6ba93dcSDouglas Gregor 
11a8b89d26SDouglas Gregor   void f1(); // expected-note{{here}}
12a8b89d26SDouglas Gregor 
13a8b89d26SDouglas Gregor   static T value; // expected-note{{here}}
14a8b89d26SDouglas Gregor };
15a8b89d26SDouglas Gregor 
16a8b89d26SDouglas Gregor template void X0<int>::f1(); // expected-error{{explicit instantiation of undefined member function}}
17a8b89d26SDouglas Gregor 
18a8b89d26SDouglas Gregor template int X0<int>::value; // expected-error{{explicit instantiation of undefined static data member}}
19a8b89d26SDouglas Gregor 
2006aa5041SDouglas Gregor template<> void f0(long); // expected-note{{previous template specialization is here}}
21*e4caa48dSRichard Smith template void f0(long); // expected-warning{{explicit instantiation of 'f0<long>' that occurs after an explicit specialization has no effect}}
22d6ba93dcSDouglas Gregor 
2306aa5041SDouglas Gregor template<> void X0<long>::f1(); // expected-note{{previous template specialization is here}}
24*e4caa48dSRichard Smith template void X0<long>::f1(); // expected-warning{{explicit instantiation of 'f1' that occurs after an explicit specialization has no effect}}
25d6ba93dcSDouglas Gregor 
2606aa5041SDouglas Gregor template<> struct X0<long>::Inner; // expected-note{{previous template specialization is here}}
27*e4caa48dSRichard Smith template struct X0<long>::Inner; // expected-warning{{explicit instantiation of 'Inner' that occurs after an explicit specialization has no effect}}
28d6ba93dcSDouglas Gregor 
2906aa5041SDouglas Gregor template<> long X0<long>::value; // expected-note{{previous template specialization is here}}
30*e4caa48dSRichard Smith template long X0<long>::value; // expected-warning{{explicit instantiation of 'value' that occurs after an explicit specialization has no effect}}
31d6ba93dcSDouglas Gregor 
3206aa5041SDouglas Gregor template<> struct X0<double>; // expected-note{{previous template specialization is here}}
33*e4caa48dSRichard Smith template struct X0<double>; // expected-warning{{explicit instantiation of 'X0<double>' that occurs after an explicit specialization has no effect}}
346b21eb5cSJohn McCall 
356b21eb5cSJohn McCall // PR 6458
366b21eb5cSJohn McCall namespace test0 {
376b21eb5cSJohn McCall   template <class T> class foo {
386b21eb5cSJohn McCall     int compare(T x, T y);
396b21eb5cSJohn McCall   };
406b21eb5cSJohn McCall 
416b21eb5cSJohn McCall   template <> int foo<char>::compare(char x, char y);
compare(T x,T y)426b21eb5cSJohn McCall   template <class T> int foo<T>::compare(T x, T y) {
436b21eb5cSJohn McCall     // invalid at T=char; if we get a diagnostic here, we're
446b21eb5cSJohn McCall     // inappropriately instantiating this template.
456b21eb5cSJohn McCall     void *ptr = x;
466b21eb5cSJohn McCall   }
47*e4caa48dSRichard Smith   extern template class foo<char>; // expected-warning 0-1{{extern templates are a C++11 extension}}
486b21eb5cSJohn McCall   template class foo<char>;
496b21eb5cSJohn McCall }
50