Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 2 | |
| 3 | // Errors |
| 4 | export class foo { }; // expected-error {{expected template}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 5 | template x; // expected-error {{C++ requires a type specifier for all declarations}} \ |
| 6 | // expected-error {{does not refer}} |
Douglas Gregor | 7cdbc58 | 2009-07-22 23:48:44 +0000 | [diff] [blame] | 7 | export template x; // expected-error {{expected '<' after 'template'}} |
Douglas Gregor | 51ffb0c | 2009-11-25 18:55:14 +0000 | [diff] [blame] | 8 | export template<class T> class x0; // expected-warning {{exported templates are unsupported}} |
David Blaikie | b031eab | 2012-04-06 23:33:59 +0000 | [diff] [blame] | 9 | template < ; // expected-error {{expected template parameter}} \ |
Douglas Gregor | 99ea734 | 2010-10-15 01:15:58 +0000 | [diff] [blame] | 10 | // expected-error{{expected ',' or '>' in template-parameter-list}} \ |
| 11 | // expected-warning {{declaration does not declare anything}} |
David Blaikie | eb52f86a | 2012-04-09 16:37:11 +0000 | [diff] [blame] | 12 | template <int +> struct x1; // expected-error {{expected ',' or '>' in template-parameter-list}} |
| 13 | |
| 14 | // verifies that we only walk to the ',' & still produce errors on the rest of the template parameters |
| 15 | template <int +, T> struct x2; // expected-error {{expected ',' or '>' in template-parameter-list}} \ |
| 16 | expected-error {{expected unqualified-id}} |
| 17 | template<template<int+>> struct x3; // expected-error {{expected ',' or '>' in template-parameter-list}} \ |
| 18 | expected-error {{template template parameter requires 'class' after the parameter list}} |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 19 | template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \ |
| 20 | // expected-error{{extraneous}} |
David Blaikie | 673720d | 2012-04-06 06:28:32 +0000 | [diff] [blame] | 21 | template <template <typename> > struct Err2; // expected-error {{template template parameter requires 'class' after the parameter list}} |
| 22 | template <template <typename> Foo> struct Err3; // expected-error {{template template parameter requires 'class' after the parameter list}} |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 23 | |
| 24 | // Template function declarations |
| 25 | template <typename T> void foo(); |
| 26 | template <typename T, typename U> void foo(); |
| 27 | |
Douglas Gregor | 26236e8 | 2008-12-02 00:41:28 +0000 | [diff] [blame] | 28 | // Template function definitions. |
| 29 | template <typename T> void foo() { } |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 30 | |
| 31 | // Template class (forward) declarations |
| 32 | template <typename T> struct A; |
| 33 | template <typename T, typename U> struct b; |
| 34 | template <typename> struct C; |
| 35 | template <typename, typename> struct D; |
| 36 | |
| 37 | // Forward declarations with default parameters? |
Douglas Gregor | 4310f4e | 2009-02-16 22:38:20 +0000 | [diff] [blame] | 38 | template <typename T = int> class X1; |
| 39 | template <typename = int> class X2; |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 40 | |
| 41 | // Forward declarations w/template template parameters |
| 42 | template <template <typename> class T> class TTP1; |
| 43 | template <template <typename> class> class TTP2; |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 44 | template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}} |
| 45 | template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}} |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 46 | template <template <typename X, typename Y> class T> class TTP5; |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 47 | |
Douglas Gregor | 52591bf | 2009-06-24 00:54:41 +0000 | [diff] [blame] | 48 | // Forward declarations with non-type params |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 49 | template <int> class NTP0; |
| 50 | template <int N> class NTP1; |
| 51 | template <int N = 5> class NTP2; |
| 52 | template <int = 10> class NTP3; |
Douglas Gregor | 4310f4e | 2009-02-16 22:38:20 +0000 | [diff] [blame] | 53 | template <unsigned int N = 12u> class NTP4; |
| 54 | template <unsigned int = 12u> class NTP5; |
| 55 | template <unsigned = 15u> class NTP6; |
| 56 | template <typename T, T Obj> class NTP7; |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 57 | |
| 58 | // Template class declarations |
| 59 | template <typename T> struct A { }; |
| 60 | template <typename T, typename U> struct B { }; |
| 61 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 62 | // Template parameter shadowing |
| 63 | template<typename T, // expected-note{{template parameter is declared here}} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 64 | typename T> // expected-error{{declaration of 'T' shadows template parameter}} |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 65 | void shadow1(); |
| 66 | |
| 67 | template<typename T> // expected-note{{template parameter is declared here}} |
| 68 | void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}} |
| 69 | |
| 70 | template<typename T> // expected-note{{template parameter is declared here}} |
| 71 | class T { // expected-error{{declaration of 'T' shadows template parameter}} |
| 72 | }; |
| 73 | |
| 74 | template<int Size> // expected-note{{template parameter is declared here}} |
| 75 | void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}} |
| 76 | |
Douglas Gregor | c19ee3e | 2009-06-17 23:37:01 +0000 | [diff] [blame] | 77 | // <rdar://problem/6952203> |
| 78 | template<typename T> // expected-note{{here}} |
| 79 | struct shadow4 { |
| 80 | int T; // expected-error{{shadows}} |
| 81 | }; |
| 82 | |
| 83 | template<typename T> // expected-note{{here}} |
| 84 | struct shadow5 { |
| 85 | int T(int, float); // expected-error{{shadows}} |
| 86 | }; |
| 87 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 88 | // Non-type template parameters in scope |
| 89 | template<int Size> |
| 90 | void f(int& i) { |
| 91 | i = Size; |
| 92 | Size = i; // expected-error{{expression is not assignable}} |
| 93 | } |
| 94 | |
| 95 | template<typename T> |
| 96 | const T& min(const T&, const T&); |
Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 97 | |
| 98 | void f2() { |
| 99 | int x; |
| 100 | A< typeof(x>1) > a; |
| 101 | } |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 102 | |
| 103 | |
| 104 | // PR3844 |
| 105 | template <> struct S<int> { }; // expected-error{{explicit specialization of non-template struct 'S'}} |
Douglas Gregor | 1df0ee9 | 2010-02-05 07:07:10 +0000 | [diff] [blame] | 106 | |
| 107 | namespace PR6184 { |
| 108 | namespace N { |
| 109 | template <typename T> |
| 110 | void bar(typename T::x); |
| 111 | } |
| 112 | |
| 113 | template <typename T> |
| 114 | void N::bar(typename T::x) { } |
| 115 | } |