blob: fc3f9fe9b9b654b9cf1e72ccf76a0412ed35f624 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor62cb18d2009-02-11 18:16:40 +00002
3template<typename T, int N = 2> struct X; // expected-note{{template is declared here}}
4
5X<int, 1> *x1;
6X<int> *x2;
7
Douglas Gregor39a8de12009-02-25 19:37:18 +00008X<> *x3; // expected-error{{too few template arguments for class template 'X'}}
Douglas Gregor62cb18d2009-02-11 18:16:40 +00009
10template<typename U = float, int M> struct X;
11
12X<> *x4;
Anders Carlsson9bff9a92009-06-05 02:12:32 +000013
Anders Carlssonf4e2a2c2009-06-05 02:45:24 +000014template<typename T = int> struct Z { };
Anders Carlsson9bff9a92009-06-05 02:12:32 +000015template struct Z<>;
Anders Carlsson3b56c002009-06-11 16:06:49 +000016
17// PR4362
18template<class T> struct a { };
19template<> struct a<int> { static const bool v = true; };
20
21template<class T, bool = a<T>::v> struct p { }; // expected-error {{no member named 'v'}}
22
23template struct p<bool>; // expected-note {{in instantiation of default argument for 'p<bool>' required here}}
24template struct p<int>;
Douglas Gregor542b5482009-10-14 17:30:58 +000025
26// PR5187
27template<typename T, typename U>
28struct A;
29
30template<typename T, typename U = T>
31struct A;
32
33template<typename T, typename U>
34struct A {
35 void f(A<T>);
36};
37
38template<typename T>
39struct B { };
40
41template<>
42struct B<void> {
43 typedef B<void*> type;
44};
Douglas Gregor0f8716b2009-11-09 19:17:50 +000045
46// Nested default arguments for template parameters.
47template<typename T> struct X1 { };
48
49template<typename T>
50struct X2 {
51 template<typename U = typename X1<T>::type> // expected-error{{no type named}}
52 struct Inner1 { };
53
54 template<T Value = X1<T>::value> // expected-error{{no member named 'value'}}
55 struct NonType1 { };
56
57 template<T Value>
58 struct Inner2 { };
59
60 template<typename U>
61 struct Inner3 {
62 template<typename X = T, typename V = U>
63 struct VeryInner { };
64
65 template<T Value1 = sizeof(T), T Value2 = sizeof(U),
66 T Value3 = Value1 + Value2>
67 struct NonType2 { };
68 };
69};
70
71X2<int> x2i;
72X2<int>::Inner1<float> x2iif;
73
74X2<int>::Inner1<> x2bad; // expected-note{{instantiation of default argument}}
75
76X2<int>::NonType1<'a'> x2_nontype1;
77X2<int>::NonType1<> x2_nontype1_bad; // expected-note{{instantiation of default argument}}
78
79// Check multi-level substitution into template type arguments
80X2<int>::Inner3<float>::VeryInner<> vi;
81X2<char>::Inner3<int>::NonType2<> x2_deep_nontype;
82
83
84template<typename T, typename U>
85struct is_same { static const bool value = false; };
86
87template<typename T>
88struct is_same<T, T> { static const bool value = true; };
89
90static int array1[is_same<__typeof__(vi),
91 X2<int>::Inner3<float>::VeryInner<int, float> >::value? 1 : -1];
92
93static int array2[is_same<__typeof(x2_deep_nontype),
94 X2<char>::Inner3<int>::NonType2<sizeof(char), sizeof(int),
95 sizeof(char)+sizeof(int)> >::value? 1 : -1];