1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat-pedantic -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++11-compat-pedantic -verify %s
3
4 #if __cplusplus < 201103L
5
6 namespace N {
f(T)7 template<typename T> void f(T) {} // expected-note 2{{here}}
8 namespace M {
9 template void ::N::f<int>(int); // expected-warning {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
10 }
11 }
12 using namespace N;
13 template void f<char>(char); // expected-warning {{explicit instantiation of 'N::f' must occur in namespace 'N'}}
14
g(T)15 template<typename T> void g(T) {} // expected-note 2{{here}}
16 namespace M {
17 template void g<int>(int); // expected-warning {{explicit instantiation of 'g' must occur at global scope}}
18 template void ::g<char>(char); // expected-warning {{explicit instantiation of 'g' must occur at global scope}}
19 }
20
21 template inline void g<double>(double); // expected-warning {{explicit instantiation cannot be 'inline'}}
22
g()23 void g() {
24 auto int n = 0; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}}
25 }
26
27 int n;
28 struct S {
29 char c;
30 }
31 s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}
32 t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}}
33
34 #define PRIuS "zu"
35 int printf(const char *, ...);
36 typedef __typeof(sizeof(int)) size_t;
h(size_t foo,size_t bar)37 void h(size_t foo, size_t bar) {
38 printf("foo is %"PRIuS", bar is %"PRIuS, foo, bar); // expected-warning 2{{identifier after literal will be treated as a reserved user-defined literal suffix in C++11}}
39 }
40
41 #define _x + 1
42 char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}}
43
f()44 template<int ...N> int f() { // expected-warning {{C++11 extension}}
45 return (N + ...); // expected-warning {{C++17 extension}}
46 }
47
48 #else
49
50 decltype(auto) x = 0; // expected-warning {{'decltype(auto)' type specifier is incompatible}}
51
__anona1f309a80102null52 auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}}
53
54 auto generic_lambda =
55 [](
56 auto // expected-warning {{generic lambdas are incompatible}}
__anona1f309a80202( auto *a) 57 *a) {};
58
59 auto deduced_return_type(); // expected-warning {{incompatible with C++ standards before C++14}}
60 auto *another_deduced_return_type(); // expected-warning {{incompatible with C++ standards before C++14}}
61 decltype(auto) also_deduced_return_type(); // expected-warning {{return type deduction}} expected-warning {{'decltype(auto)' type specifier is incompatible}}
62 int f();
63 auto (*not_deduced_return_type)() = f;
64
65 auto deduced_lambda_return_type = []() ->
66 auto // expected-warning {{return type deduction is incompatible}}
__anona1f309a80302() 67 {};
68
69 auto trailing_non_deduced_return_type() -> int;
70 auto trailing_deduced_return_type() -> auto; // expected-warning {{incompatible with C++ standards before C++14}}
71
72 struct A {
73 operator auto(); // expected-warning {{return type deduction is incompatible}}
74 };
75
76 #endif
77