blob: bcf0cf11dc183ff8f04e1d9ce8e4944f725c0cb0 [file] [log] [blame]
David Blaikiecc5f8f02011-10-18 05:54:07 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat -verify %s
Richard Smith085a64f2014-06-20 19:57:12 +00002// RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++11-compat -verify %s
Richard Smith5b013f52013-09-28 05:38:27 +00003
4#if __cplusplus < 201103L
Richard Smith81285492011-10-11 17:38:48 +00005
6namespace N {
Richard Smith050d2612011-10-18 02:28:33 +00007 template<typename T> void f(T) {} // expected-note 2{{here}}
Richard Smith81285492011-10-11 17:38:48 +00008 namespace M {
Richard Smith050d2612011-10-18 02:28:33 +00009 template void ::N::f<int>(int); // expected-warning {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
Richard Smith81285492011-10-11 17:38:48 +000010 }
11}
Richard Smith050d2612011-10-18 02:28:33 +000012using namespace N;
13template void f<char>(char); // expected-warning {{explicit instantiation of 'N::f' must occur in namespace 'N'}}
Richard Smith81285492011-10-11 17:38:48 +000014
Richard Smith050d2612011-10-18 02:28:33 +000015template<typename T> void g(T) {} // expected-note 2{{here}}
Richard Smith81285492011-10-11 17:38:48 +000016namespace M {
Richard Smith050d2612011-10-18 02:28:33 +000017 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}}
Richard Smith81285492011-10-11 17:38:48 +000019}
20
Richard Smith83c19292011-10-18 03:44:03 +000021template inline void g<double>(double); // expected-warning {{explicit instantiation cannot be 'inline'}}
22
Richard Smith050d2612011-10-18 02:28:33 +000023void g() {
Douglas Gregor205d0442011-10-12 19:26:40 +000024 auto int n = 0; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}}
Richard Smith81285492011-10-11 17:38:48 +000025}
26
27int n;
28struct S {
29 char c;
30}
Douglas Gregor205d0442011-10-12 19:26:40 +000031s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}
32t = { 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}}
Richard Smith3e4a60a2012-03-07 03:13:00 +000033
34#define PRIuS "uS"
35int printf(const char *, ...);
36typedef __typeof(sizeof(int)) size_t;
37void h(size_t foo, size_t bar) {
Richard Smith0df56f42012-03-08 02:39:21 +000038 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}}
Richard Smith3e4a60a2012-03-07 03:13:00 +000039}
40
Richard Smith0df56f42012-03-08 02:39:21 +000041#define _x + 1
42char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}}
Richard Smith5b013f52013-09-28 05:38:27 +000043
Richard Smith0f0af192014-11-08 05:07:16 +000044template<int ...N> int f() { // expected-warning {{C++11 extension}}
45 return (N + ...); // expected-warning {{C++1z extension}}
46}
47
Richard Smith5b013f52013-09-28 05:38:27 +000048#else
49
Aaron Ballmandd69ef32014-08-19 15:55:55 +000050auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}}
Richard Smith085a64f2014-06-20 19:57:12 +000051static_assert(true); // expected-warning {{incompatible with C++ standards before C++1z}}
Richard Smith5b013f52013-09-28 05:38:27 +000052
Richard Smith0f0af192014-11-08 05:07:16 +000053template<int ...N> int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++1z}}
54
Richard Smith5b013f52013-09-28 05:38:27 +000055#endif