Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 2 | template<typename T, typename U = int> struct A; // expected-note{{template is declared here}} |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 3 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 4 | template<> struct A<double, double>; // expected-note{{forward declaration}} |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 5 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 6 | template<> struct A<float, float> { // expected-note{{previous definition}} |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 7 | int x; |
| 8 | }; |
| 9 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 10 | template<> struct A<float> { // expected-note{{previous definition}} |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 11 | int y; |
| 12 | }; |
| 13 | |
| 14 | int test_specs(A<float, float> *a1, A<float, int> *a2) { |
| 15 | return a1->x + a2->y; |
| 16 | } |
| 17 | |
| 18 | int test_incomplete_specs(A<double, double> *a1, |
| 19 | A<double> *a2) // FIXME: expected-note{{forward declaration}} |
| 20 | { |
| 21 | (void)a1->x; // expected-error{{incomplete definition of type 'A<double, double>'}} |
| 22 | (void)a2->x; // expected-error{{incomplete definition of type 'A<double>'}} |
| 23 | } |
| 24 | |
| 25 | typedef float FLOAT; |
| 26 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 27 | template<> struct A<float, FLOAT>; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 28 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 29 | template<> struct A<FLOAT, float> { }; // expected-error{{redefinition}} |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 30 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 31 | template<> struct A<float, int> { }; // expected-error{{redefinition}} |
Douglas Gregor | 611a8c4 | 2009-02-19 00:52:42 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 33 | template<typename T, typename U = int> struct X; |
Douglas Gregor | 611a8c4 | 2009-02-19 00:52:42 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 35 | template <> struct X<int, int> { int foo(); }; // #1 |
| 36 | template <> struct X<float> { int bar(); }; // #2 |
Douglas Gregor | 611a8c4 | 2009-02-19 00:52:42 +0000 | [diff] [blame] | 37 | |
| 38 | typedef int int_type; |
| 39 | void testme(X<int_type> *x1, X<float, int> *x2) { |
| 40 | x1->foo(); // okay: refers to #1 |
| 41 | x2->bar(); // okay: refers to #2 |
| 42 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 43 | |
Douglas Gregor | ac1afdc | 2009-02-25 19:48:02 +0000 | [diff] [blame] | 44 | // Diagnose specializations in a different namespace |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame^] | 45 | struct A<double> { }; // expected-error{{template specialization requires 'template<>'}} |
| 46 | |
| 47 | template<typename T> // expected-error{{class template partial specialization is not yet supported}} |
| 48 | struct A<T*> { }; |
| 49 | |
| 50 | template<> struct ::A<double>; |
| 51 | |
| 52 | namespace N { |
| 53 | template<typename T> struct B; // expected-note 2{{template is declared here}} |
| 54 | |
| 55 | template<> struct ::N::B<short>; // okay |
| 56 | template<> struct ::N::B<int>; // okay |
| 57 | } |
| 58 | |
| 59 | template<> struct N::B<int> { }; // okay |
| 60 | |
| 61 | template<> struct N::B<float> { }; // expected-error{{class template specialization of 'B' not in namespace 'N'}} |
| 62 | |
| 63 | namespace M { |
| 64 | template<> struct ::N::B<short> { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} |
| 65 | |
| 66 | template<> struct ::A<long double>; // expected-error{{class template specialization of 'A' must occur in the global scope}} |
| 67 | } |