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