xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/class-template-id.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc template<typename T, typename U = float> struct A { };
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc typedef A<int> A_int;
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc typedef float FLOAT;
7*f4a2713aSLionel Sambuc 
foo(A<int> * ptr,A<int> const * ptr2,A<int,double> * ptr3)8*f4a2713aSLionel Sambuc A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {
9*f4a2713aSLionel Sambuc   if (ptr)
10*f4a2713aSLionel Sambuc     return ptr; // okay
11*f4a2713aSLionel Sambuc   else if (ptr2)
12*f4a2713aSLionel Sambuc     return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'const A<int> *'}}
13*f4a2713aSLionel Sambuc   else {
14*f4a2713aSLionel Sambuc     return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'A<int, double> *'}}
15*f4a2713aSLionel Sambuc   }
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc template<int I> struct B;
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc const int value = 12;
bar(B<(19)> * ptr1,B<(::value+7)> * ptr2,B<19-3> * ptr3)21*f4a2713aSLionel Sambuc B<17 + 2> *bar(B<(19)> *ptr1, B< (::value + 7) > *ptr2, B<19 - 3> *ptr3) {
22*f4a2713aSLionel Sambuc   if (ptr1)
23*f4a2713aSLionel Sambuc     return ptr1;
24*f4a2713aSLionel Sambuc   else if (ptr2)
25*f4a2713aSLionel Sambuc     return ptr2;
26*f4a2713aSLionel Sambuc   else
27*f4a2713aSLionel Sambuc     return ptr3; // expected-error{{cannot initialize return object of type 'B<17 + 2> *' with an lvalue of type 'B<19 - 3>}}
28*f4a2713aSLionel Sambuc }
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc typedef B<5> B5;
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc namespace N {
34*f4a2713aSLionel Sambuc   template<typename T> struct C {};
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc N::C<int> c1;
38*f4a2713aSLionel Sambuc typedef N::C<float> c2;
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc // PR5655
41*f4a2713aSLionel Sambuc template<typename T> struct Foo { }; // expected-note{{template is declared here}}
42*f4a2713aSLionel Sambuc 
f(void)43*f4a2713aSLionel Sambuc void f(void) { Foo bar; } // expected-error{{use of class template 'Foo' requires template arguments}}
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc // rdar://problem/8254267
46*f4a2713aSLionel Sambuc template <typename T> class Party;
47*f4a2713aSLionel Sambuc template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}
48