xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/cxx11-templates.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc struct S {
4*0a6a1f1dSLionel Sambuc   template <typename Ty = char>
5*0a6a1f1dSLionel Sambuc   static_assert(sizeof(Ty) != 1, "Not a char"); // expected-error {{a static_assert declaration cannot be a template}}
6*0a6a1f1dSLionel Sambuc };
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc template <typename Ty = char>
9*0a6a1f1dSLionel Sambuc static_assert(sizeof(Ty) != 1, "Not a char"); // expected-error {{a static_assert declaration cannot be a template}}
10*0a6a1f1dSLionel Sambuc 
11*0a6a1f1dSLionel Sambuc namespace Ellipsis {
12*0a6a1f1dSLionel Sambuc   template<typename ...T> void f(T t..., int n); // expected-error {{must immediately precede declared identifier}}
13*0a6a1f1dSLionel Sambuc   template<typename ...T> void f(int n, T t...); // expected-error {{must immediately precede declared identifier}}
14*0a6a1f1dSLionel Sambuc   template<typename ...T> void f(int n, T t, ...); // expected-error {{unexpanded parameter pack}}
f()15*0a6a1f1dSLionel Sambuc   template<typename ...T> void f() {
16*0a6a1f1dSLionel Sambuc     f([]{
17*0a6a1f1dSLionel Sambuc       void g(T
18*0a6a1f1dSLionel Sambuc              t // expected-note {{place '...' immediately before declared identifier to declare a function parameter pack}}
19*0a6a1f1dSLionel Sambuc              ... // expected-warning {{'...' in this location creates a C-style varargs function, not a function parameter pack}}
20*0a6a1f1dSLionel Sambuc              // expected-note@-1 {{insert ',' before '...' to silence this warning}}
21*0a6a1f1dSLionel Sambuc              );
22*0a6a1f1dSLionel Sambuc       void h(T (&
23*0a6a1f1dSLionel Sambuc               ) // expected-note {{place '...' here to declare a function parameter pack}}
24*0a6a1f1dSLionel Sambuc              ... // expected-warning {{'...' in this location creates a C-style varargs function, not a function parameter pack}}
25*0a6a1f1dSLionel Sambuc              // expected-note@-1 {{insert ',' before '...' to silence this warning}}
26*0a6a1f1dSLionel Sambuc              );
27*0a6a1f1dSLionel Sambuc       void i(T (&), ...);
28*0a6a1f1dSLionel Sambuc     }...);
29*0a6a1f1dSLionel Sambuc   }
30*0a6a1f1dSLionel Sambuc   template<typename ...T> struct S {
31*0a6a1f1dSLionel Sambuc     void f(T t...); // expected-error {{must immediately precede declared identifier}}
32*0a6a1f1dSLionel Sambuc     void f(T ... // expected-note {{preceding '...' declares a function parameter pack}}
33*0a6a1f1dSLionel Sambuc            t...); // expected-warning-re {{'...' in this location creates a C-style varargs function{{$}}}}
34*0a6a1f1dSLionel Sambuc            // expected-note@-1 {{insert ',' before '...' to silence this warning}}
35*0a6a1f1dSLionel Sambuc   };
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc   // FIXME: We should just issue a single error in this case pointing out where
38*0a6a1f1dSLionel Sambuc   // the '...' goes. It's tricky to recover correctly in this case, though,
39*0a6a1f1dSLionel Sambuc   // because the parameter is in scope in the default argument, so must be
40*0a6a1f1dSLionel Sambuc   // passed to Sema before we reach the ellipsis.
41*0a6a1f1dSLionel Sambuc   template<typename...T> void f(T n = 1 ...);
42*0a6a1f1dSLionel Sambuc   // expected-warning@-1 {{creates a C-style varargs}}
43*0a6a1f1dSLionel Sambuc   // expected-note@-2 {{place '...' immediately before declared identifier}}
44*0a6a1f1dSLionel Sambuc   // expected-note@-3 {{insert ','}}
45*0a6a1f1dSLionel Sambuc   // expected-error@-4 {{unexpanded parameter pack}}
46*0a6a1f1dSLionel Sambuc }
47