blob: 9b8ca985ddd90239cd49ac0e5438981489362a15 [file] [log] [blame]
Eli Friedmanaffd5fd2009-12-27 22:31:18 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Charles Li85dec552015-12-10 01:07:17 +00002// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Faisal Valicb7e5df2013-12-04 03:51:14 +00004// RUN: %clang_cc1 -fsyntax-only -verify %s -fdelayed-template-parsing
Charles Li85dec552015-12-10 01:07:17 +00005// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -fdelayed-template-parsing
6// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -fdelayed-template-parsing
Eli Friedmanaffd5fd2009-12-27 22:31:18 +00007
8template<typename T> struct A {};
9
10// Check for template argument lists followed by junk
11// FIXME: The diagnostics here aren't great...
12A<int+> int x; // expected-error {{expected '>'}} expected-error {{expected unqualified-id}}
Richard Smith9ce302e2013-07-11 05:10:21 +000013A<int x; // expected-error {{type-id cannot have a name}} expected-error {{expected '>'}}
Eli Friedmanaffd5fd2009-12-27 22:31:18 +000014
Douglas Gregor94a32472011-01-11 00:33:19 +000015// PR8912
16template <bool> struct S {};
17S<bool(2 > 1)> s;
Richard Smith7b3f3222012-06-18 06:11:04 +000018
19// Test behavior when a template-id is ended by a token which starts with '>'.
20namespace greatergreater {
21 template<typename T> struct S { S(); S(T); };
22 void f(S<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}}
23 void f(S<S<int>>=S<int>()); // expected-error {{use '> >'}} expected-error {{use '> ='}}
24 template<typename T> void t();
25 void g() {
26 void (*p)() = &t<int>;
27 (void)(&t<int>==p); // expected-error {{use '> ='}}
28 (void)(&t<int>>=p); // expected-error {{use '> >'}}
Charles Li85dec552015-12-10 01:07:17 +000029 (void)(&t<S<int>>>=p);
30#if __cplusplus <= 199711L
31 // expected-error@-2 {{use '> >'}}
32#endif
Richard Smith7b3f3222012-06-18 06:11:04 +000033 (void)(&t<S<int>>==p); // expected-error {{use '> >'}} expected-error {{use '> ='}}
34 }
35}
Richard Smith4f605af2012-08-18 00:55:03 +000036
37namespace PR5925 {
38 template <typename x>
39 class foo { // expected-note {{here}}
40 };
41 void bar(foo *X) { // expected-error {{requires template arguments}}
42 }
43}
44
45namespace PR13210 {
46 template <class T>
47 class C {}; // expected-note {{here}}
48
49 void f() {
50 new C(); // expected-error {{requires template arguments}}
51 }
52}
Serge Pavlovb716b3c2013-08-10 05:54:47 +000053
54// Don't emit spurious messages
55namespace pr16225add {
56
57 template<class T1, typename T2> struct Known { }; // expected-note 3 {{template is declared here}}
58 template<class T1, typename T2> struct X;
59 template<class T1, typename T2> struct ABC; // expected-note {{template is declared here}}
60 template<int N1, int N2> struct ABC2 {};
61
62 template<class T1, typename T2> struct foo :
63 UnknownBase<T1,T2> // expected-error {{unknown template name 'UnknownBase'}}
64 { };
65
66 template<class T1, typename T2> struct foo2 :
67 UnknownBase<T1,T2>, // expected-error {{unknown template name 'UnknownBase'}}
68 Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
69 { };
70
71 template<class T1, typename T2> struct foo3 :
72 UnknownBase<T1,T2,ABC<T2,T1> > // expected-error {{unknown template name 'UnknownBase'}}
73 { };
74
75 template<class T1, typename T2> struct foo4 :
76 UnknownBase<T1,ABC<T2> >, // expected-error {{unknown template name 'UnknownBase'}} \
77 // expected-error {{too few template arguments for class template 'ABC'}}
78 Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
79 { };
80
81 template<class T1, typename T2> struct foo5 :
Charles Li85dec552015-12-10 01:07:17 +000082 UnknownBase<T1,T2,ABC<T2,T1>> // expected-error {{unknown template name 'UnknownBase'}}
83#if __cplusplus <= 199711L
84 // expected-error@-2 {{use '> >'}}
85#endif
Serge Pavlovb716b3c2013-08-10 05:54:47 +000086 { };
87
88 template<class T1, typename T2> struct foo6 :
Charles Li85dec552015-12-10 01:07:17 +000089 UnknownBase<T1,ABC<T2,T1>>, // expected-error {{unknown template name 'UnknownBase'}}
90#if __cplusplus <= 199711L
91 // expected-error@-2 {{use '> >'}}
92#endif
Serge Pavlovb716b3c2013-08-10 05:54:47 +000093 Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
94 { };
95
96 template<class T1, typename T2, int N> struct foo7 :
97 UnknownBase<T1,T2,(N>1)> // expected-error {{unknown template name 'UnknownBase'}}
98 { };
99
100 template<class T1, typename T2> struct foo8 :
Charles Li85dec552015-12-10 01:07:17 +0000101 UnknownBase<X<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}}
102#if __cplusplus <= 199711L
103 // expected-error@-2 {{use '> >'}}
104#endif
Serge Pavlovb716b3c2013-08-10 05:54:47 +0000105 { };
106
107 template<class T1, typename T2> struct foo9 :
Charles Li85dec552015-12-10 01:07:17 +0000108 UnknownBase<Known<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}}
109#if __cplusplus <= 199711L
110 // expected-error@-2 {{use '> >'}}
111#endif
Serge Pavlovb716b3c2013-08-10 05:54:47 +0000112 { };
113
114 template<class T1, typename T2> struct foo10 :
Charles Li85dec552015-12-10 01:07:17 +0000115 UnknownBase<Known<int,int>,X<int,X<int,int>>> // expected-error {{unknown template name 'UnknownBase'}}
116#if __cplusplus <= 199711L
117 // expected-error@-2 {{use '> >'}}
118#endif
Serge Pavlovb716b3c2013-08-10 05:54:47 +0000119 { };
120
121 template<int N1, int N2> struct foo11 :
122 UnknownBase<2<N1,N2<4> // expected-error {{unknown template name 'UnknownBase'}}
123 { };
124
125}
Richard Smithbdf54a212014-09-23 21:05:52 +0000126
127namespace PR18793 {
128 template<typename T, T> struct S {};
129 template<typename T> int g(S<T, (T())> *);
130}