annotate clang/test/Parser/cxx11-templates.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 struct S {
anatofuz
parents:
diff changeset
4 template <typename Ty = char>
anatofuz
parents:
diff changeset
5 static_assert(sizeof(Ty) != 1, "Not a char"); // expected-error {{a static_assert declaration cannot be a template}}
anatofuz
parents:
diff changeset
6 };
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 template <typename Ty = char>
anatofuz
parents:
diff changeset
9 static_assert(sizeof(Ty) != 1, "Not a char"); // expected-error {{a static_assert declaration cannot be a template}}
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 namespace Ellipsis {
anatofuz
parents:
diff changeset
12 template<typename ...T> void f(T t..., int n); // expected-error {{must immediately precede declared identifier}}
anatofuz
parents:
diff changeset
13 template<typename ...T> void f(int n, T t...); // expected-error {{must immediately precede declared identifier}}
anatofuz
parents:
diff changeset
14 template<typename ...T> void f(int n, T t, ...); // expected-error {{unexpanded parameter pack}}
anatofuz
parents:
diff changeset
15 template<typename ...T> void f() {
anatofuz
parents:
diff changeset
16 f([]{
anatofuz
parents:
diff changeset
17 void g(T
anatofuz
parents:
diff changeset
18 t // expected-note {{place '...' immediately before declared identifier to declare a function parameter pack}}
anatofuz
parents:
diff changeset
19 ... // expected-warning {{'...' in this location creates a C-style varargs function, not a function parameter pack}}
anatofuz
parents:
diff changeset
20 // expected-note@-1 {{insert ',' before '...' to silence this warning}}
anatofuz
parents:
diff changeset
21 );
anatofuz
parents:
diff changeset
22 void h(T (&
anatofuz
parents:
diff changeset
23 ) // expected-note {{place '...' here to declare a function parameter pack}}
anatofuz
parents:
diff changeset
24 ... // expected-warning {{'...' in this location creates a C-style varargs function, not a function parameter pack}}
anatofuz
parents:
diff changeset
25 // expected-note@-1 {{insert ',' before '...' to silence this warning}}
anatofuz
parents:
diff changeset
26 );
anatofuz
parents:
diff changeset
27 void i(T (&), ...);
anatofuz
parents:
diff changeset
28 }...);
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30 template<typename ...T> struct S {
anatofuz
parents:
diff changeset
31 void f(T t...); // expected-error {{must immediately precede declared identifier}}
anatofuz
parents:
diff changeset
32 void f(T ... // expected-note {{preceding '...' declares a function parameter pack}}
anatofuz
parents:
diff changeset
33 t...); // expected-warning-re {{'...' in this location creates a C-style varargs function{{$}}}}
anatofuz
parents:
diff changeset
34 // expected-note@-1 {{insert ',' before '...' to silence this warning}}
anatofuz
parents:
diff changeset
35 };
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // FIXME: We should just issue a single error in this case pointing out where
anatofuz
parents:
diff changeset
38 // the '...' goes. It's tricky to recover correctly in this case, though,
anatofuz
parents:
diff changeset
39 // because the parameter is in scope in the default argument, so must be
anatofuz
parents:
diff changeset
40 // passed to Sema before we reach the ellipsis.
anatofuz
parents:
diff changeset
41 template<typename...T> void f(T n = 1 ...);
anatofuz
parents:
diff changeset
42 // expected-warning@-1 {{creates a C-style varargs}}
anatofuz
parents:
diff changeset
43 // expected-note@-2 {{place '...' immediately before declared identifier}}
anatofuz
parents:
diff changeset
44 // expected-note@-3 {{insert ','}}
anatofuz
parents:
diff changeset
45 // expected-error@-4 {{unexpanded parameter pack}}
anatofuz
parents:
diff changeset
46 }