xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/cxx0x-compat.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat -verify %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++11-compat -verify %s
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc #if __cplusplus < 201103L
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc namespace N {
f(T)7f4a2713aSLionel Sambuc   template<typename T> void f(T) {} // expected-note 2{{here}}
8f4a2713aSLionel Sambuc   namespace M {
9f4a2713aSLionel Sambuc     template void ::N::f<int>(int); // expected-warning {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
10f4a2713aSLionel Sambuc   }
11f4a2713aSLionel Sambuc }
12f4a2713aSLionel Sambuc using namespace N;
13f4a2713aSLionel Sambuc template void f<char>(char); // expected-warning {{explicit instantiation of 'N::f' must occur in namespace 'N'}}
14f4a2713aSLionel Sambuc 
g(T)15f4a2713aSLionel Sambuc template<typename T> void g(T) {} // expected-note 2{{here}}
16f4a2713aSLionel Sambuc namespace M {
17f4a2713aSLionel Sambuc   template void g<int>(int); // expected-warning {{explicit instantiation of 'g' must occur at global scope}}
18f4a2713aSLionel Sambuc   template void ::g<char>(char); // expected-warning {{explicit instantiation of 'g' must occur at global scope}}
19f4a2713aSLionel Sambuc }
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc template inline void g<double>(double); // expected-warning {{explicit instantiation cannot be 'inline'}}
22f4a2713aSLionel Sambuc 
g()23f4a2713aSLionel Sambuc void g() {
24f4a2713aSLionel Sambuc   auto int n = 0; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}}
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc int n;
28f4a2713aSLionel Sambuc struct S {
29f4a2713aSLionel Sambuc   char c;
30f4a2713aSLionel Sambuc }
31f4a2713aSLionel Sambuc 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}}
32f4a2713aSLionel Sambuc 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}}
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc #define PRIuS "uS"
35f4a2713aSLionel Sambuc int printf(const char *, ...);
36f4a2713aSLionel Sambuc typedef __typeof(sizeof(int)) size_t;
h(size_t foo,size_t bar)37f4a2713aSLionel Sambuc void h(size_t foo, size_t bar) {
38f4a2713aSLionel Sambuc   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}}
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc #define _x + 1
42f4a2713aSLionel Sambuc char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}}
43f4a2713aSLionel Sambuc 
f()44*0a6a1f1dSLionel Sambuc template<int ...N> int f() { // expected-warning {{C++11 extension}}
45*0a6a1f1dSLionel Sambuc   return (N + ...); // expected-warning {{C++1z extension}}
46*0a6a1f1dSLionel Sambuc }
47*0a6a1f1dSLionel Sambuc 
48f4a2713aSLionel Sambuc #else
49f4a2713aSLionel Sambuc 
__anon7b21bf4a0102null50*0a6a1f1dSLionel Sambuc auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}}
51*0a6a1f1dSLionel Sambuc static_assert(true); // expected-warning {{incompatible with C++ standards before C++1z}}
52*0a6a1f1dSLionel Sambuc 
f()53*0a6a1f1dSLionel Sambuc template<int ...N> int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++1z}}
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc #endif
56