Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 2 | template<typename T, typename U = float> struct A { }; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 3 | |
| 4 | typedef A<int> A_int; |
| 5 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 6 | typedef float FLOAT; |
| 7 | |
| 8 | A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) { |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 9 | if (ptr) |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 10 | return ptr; // okay |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 11 | else if (ptr2) |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 12 | return ptr2; // expected-error{{incompatible type returning 'A<int> const *', expected 'A<int, FLOAT> *'}} |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 13 | else { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 14 | return ptr3; // expected-error{{incompatible type returning 'A<int, double> *', expected 'A<int, FLOAT> *'}} |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 15 | } |
| 16 | } |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 17 | |
| 18 | template<int I> struct B; |
| 19 | |
| 20 | const int value = 12; |
| 21 | B<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 |
| 27 | return ptr3; // expected-error{{incompatible type returning 'B<19 - 3> *', expected 'B<17 + 2> *'}} |
| 28 | } |
| 29 | |
Douglas Gregor | a35b1d5 | 2009-03-17 23:49:44 +0000 | [diff] [blame] | 30 | typedef B<5> B5; |
Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 31 | |
| 32 | |
| 33 | namespace N { |
| 34 | template<typename T> struct C {}; |
| 35 | } |
| 36 | |
| 37 | N::C<int> c1; |
| 38 | typedef N::C<float> c2; |
Douglas Gregor | 9af2f52 | 2009-12-01 16:58:18 +0000 | [diff] [blame] | 39 | |
| 40 | // PR5655 |
| 41 | template<typename T> struct Foo { }; // expected-note{{template is declared here}} |
| 42 | |
| 43 | void f(void) { Foo bar; } // expected-error{{without a template argument list}} |