Clang Project

clang_source_code/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3struct IntHolder {
4  IntHolder(int);
5};
6
7template<typename T, typename U>
8struct X {
9  void f() { 
10    T t;
11  }
12  
13  void g() { }
14  
15  struct Inner { 
16    T value; 
17  };
18  
19  static T value;
20};
21
22template<typename T, typename U>
23T X<T, U>::value;
24
25// Explicitly specialize the members of X<IntHolder, long> to not cause
26// problems with instantiation, but only provide declarations (not definitions).
27template<>
28void X<IntHolder, long>::f();
29
30template<>
31struct X<IntHolder, long>::Inner; // expected-note{{forward declaration}}
32
33template<>
34IntHolder X<IntHolder, long>::value;
35
36IntHolder &test_X_IntHolderInt(X<IntHolder, long> xih) {
37  xih.g(); // okay
38  xih.f(); // okay, uses specialization
39  
40  X<IntHolder, long>::Inner inner; // expected-error {{incomplete}}
41  
42  return X<IntHolder, long>::value; // okay, uses specialization
43}
44
45
46template<class T> struct A {
47  void f(T) { /* ... */ }
48};
49
50template<> struct A<int> { 
51  void f(int);
52};
53
54void h() {
55  A<int> a; 
56  a.f(16); // A<int>::f must be defined somewhere
57}
58
59// explicit specialization syntax not used for a member of 
60// explicitly specialized class template specialization 
61void A<int>::f(int) { /* ... */ }
62