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