blob: c9cc6b8079028ed36cd2b1d570df8eeb5b87afbf [file] [log] [blame]
Eli Friedman64a4eb22009-12-27 22:31:18 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Stephen Hines651f13c2014-04-23 16:59:28 -07002// RUN: %clang_cc1 -fsyntax-only -verify %s -fdelayed-template-parsing
Eli Friedman64a4eb22009-12-27 22:31:18 +00003
4template<typename T> struct A {};
5
6// Check for template argument lists followed by junk
7// FIXME: The diagnostics here aren't great...
8A<int+> int x; // expected-error {{expected '>'}} expected-error {{expected unqualified-id}}
Richard Smitha38253c2013-07-11 05:10:21 +00009A<int x; // expected-error {{type-id cannot have a name}} expected-error {{expected '>'}}
Eli Friedman64a4eb22009-12-27 22:31:18 +000010
Douglas Gregorbc61bd82011-01-11 00:33:19 +000011// PR8912
12template <bool> struct S {};
13S<bool(2 > 1)> s;
Richard Smith19a27022012-06-18 06:11:04 +000014
15// Test behavior when a template-id is ended by a token which starts with '>'.
16namespace greatergreater {
17 template<typename T> struct S { S(); S(T); };
18 void f(S<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}}
19 void f(S<S<int>>=S<int>()); // expected-error {{use '> >'}} expected-error {{use '> ='}}
20 template<typename T> void t();
21 void g() {
22 void (*p)() = &t<int>;
23 (void)(&t<int>==p); // expected-error {{use '> ='}}
24 (void)(&t<int>>=p); // expected-error {{use '> >'}}
25 (void)(&t<S<int>>>=p); // expected-error {{use '> >'}}
26 (void)(&t<S<int>>==p); // expected-error {{use '> >'}} expected-error {{use '> ='}}
27 }
28}
Richard Smith05766812012-08-18 00:55:03 +000029
30namespace PR5925 {
31 template <typename x>
32 class foo { // expected-note {{here}}
33 };
34 void bar(foo *X) { // expected-error {{requires template arguments}}
35 }
36}
37
38namespace PR13210 {
39 template <class T>
40 class C {}; // expected-note {{here}}
41
42 void f() {
43 new C(); // expected-error {{requires template arguments}}
44 }
45}
Serge Pavlov62f675c2013-08-10 05:54:47 +000046
47// Don't emit spurious messages
48namespace pr16225add {
49
50 template<class T1, typename T2> struct Known { }; // expected-note 3 {{template is declared here}}
51 template<class T1, typename T2> struct X;
52 template<class T1, typename T2> struct ABC; // expected-note {{template is declared here}}
53 template<int N1, int N2> struct ABC2 {};
54
55 template<class T1, typename T2> struct foo :
56 UnknownBase<T1,T2> // expected-error {{unknown template name 'UnknownBase'}}
57 { };
58
59 template<class T1, typename T2> struct foo2 :
60 UnknownBase<T1,T2>, // expected-error {{unknown template name 'UnknownBase'}}
61 Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
62 { };
63
64 template<class T1, typename T2> struct foo3 :
65 UnknownBase<T1,T2,ABC<T2,T1> > // expected-error {{unknown template name 'UnknownBase'}}
66 { };
67
68 template<class T1, typename T2> struct foo4 :
69 UnknownBase<T1,ABC<T2> >, // expected-error {{unknown template name 'UnknownBase'}} \
70 // expected-error {{too few template arguments for class template 'ABC'}}
71 Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
72 { };
73
74 template<class T1, typename T2> struct foo5 :
75 UnknownBase<T1,T2,ABC<T2,T1>> // expected-error {{unknown template name 'UnknownBase'}} \
76 // expected-error {{use '> >'}}
77 { };
78
79 template<class T1, typename T2> struct foo6 :
80 UnknownBase<T1,ABC<T2,T1>>, // expected-error {{unknown template name 'UnknownBase'}} \
81 // expected-error {{use '> >'}}
82 Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
83 { };
84
85 template<class T1, typename T2, int N> struct foo7 :
86 UnknownBase<T1,T2,(N>1)> // expected-error {{unknown template name 'UnknownBase'}}
87 { };
88
89 template<class T1, typename T2> struct foo8 :
90 UnknownBase<X<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}} \
91 // expected-error {{use '> >'}}
92 { };
93
94 template<class T1, typename T2> struct foo9 :
95 UnknownBase<Known<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}} \
96 // expected-error {{use '> >'}}
97 { };
98
99 template<class T1, typename T2> struct foo10 :
100 UnknownBase<Known<int,int>,X<int,X<int,int>>> // expected-error {{unknown template name 'UnknownBase'}} \
101 // expected-error {{use '> >'}}
102 { };
103
104 template<int N1, int N2> struct foo11 :
105 UnknownBase<2<N1,N2<4> // expected-error {{unknown template name 'UnknownBase'}}
106 { };
107
108}
Stephen Hines176edba2014-12-01 14:53:08 -0800109
110namespace PR18793 {
111 template<typename T, T> struct S {};
112 template<typename T> int g(S<T, (T())> *);
113}