blob: 3b027787249b3356ad3150ea4094c3954e822427 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor3e00bad2009-02-17 01:05:43 +00002template<typename T, typename U = float> struct A { };
Douglas Gregor55f6b142009-02-09 18:46:07 +00003
4typedef A<int> A_int;
5
Douglas Gregor3e00bad2009-02-17 01:05:43 +00006typedef float FLOAT;
7
8A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {
Douglas Gregor55f6b142009-02-09 18:46:07 +00009 if (ptr)
Douglas Gregor3e00bad2009-02-17 01:05:43 +000010 return ptr; // okay
Douglas Gregor55f6b142009-02-09 18:46:07 +000011 else if (ptr2)
Chris Lattner2f69a812010-09-05 00:27:00 +000012 return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'const A<int> *'}}
Douglas Gregor55f6b142009-02-09 18:46:07 +000013 else {
Douglas Gregor18ef5e22009-12-18 05:02:21 +000014 return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'A<int, double> *'}}
Douglas Gregor55f6b142009-02-09 18:46:07 +000015 }
16}
Douglas Gregor3e00bad2009-02-17 01:05:43 +000017
18template<int I> struct B;
19
20const int value = 12;
21B<17 + 2> *bar(B<(19)> *ptr1, B< (::value + 7) > *ptr2, B<19 - 3> *ptr3) {
22 if (ptr1)
23 return ptr1;
24 else if (ptr2)
25 return ptr2;
26 else
Douglas Gregor18ef5e22009-12-18 05:02:21 +000027 return ptr3; // expected-error{{cannot initialize return object of type 'B<17 + 2> *' with an lvalue of type 'B<19 - 3>}}
Douglas Gregor3e00bad2009-02-17 01:05:43 +000028}
29
Douglas Gregora35b1d52009-03-17 23:49:44 +000030typedef B<5> B5;
Douglas Gregor9135c722009-03-25 15:40:00 +000031
32
33namespace N {
34 template<typename T> struct C {};
35}
36
37N::C<int> c1;
38typedef N::C<float> c2;
Douglas Gregor9af2f522009-12-01 16:58:18 +000039
40// PR5655
41template<typename T> struct Foo { }; // expected-note{{template is declared here}}
42
43void f(void) { Foo bar; } // expected-error{{without a template argument list}}
John McCall207014e2010-07-30 06:26:29 +000044
45// rdar://problem/8254267
46template <typename T> class Party;
47template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}