David Blaikie | cc5f8f0 | 2011-10-18 05:54:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat -verify %s |
Richard Smith | 085a64f | 2014-06-20 19:57:12 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++11-compat -verify %s |
Richard Smith | 5b013f5 | 2013-09-28 05:38:27 +0000 | [diff] [blame] | 3 | |
| 4 | #if __cplusplus < 201103L |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 5 | |
| 6 | namespace N { |
Richard Smith | 050d261 | 2011-10-18 02:28:33 +0000 | [diff] [blame] | 7 | template<typename T> void f(T) {} // expected-note 2{{here}} |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 8 | namespace M { |
Richard Smith | 050d261 | 2011-10-18 02:28:33 +0000 | [diff] [blame] | 9 | template void ::N::f<int>(int); // expected-warning {{explicit instantiation of 'f' not in a namespace enclosing 'N'}} |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 10 | } |
| 11 | } |
Richard Smith | 050d261 | 2011-10-18 02:28:33 +0000 | [diff] [blame] | 12 | using namespace N; |
| 13 | template void f<char>(char); // expected-warning {{explicit instantiation of 'N::f' must occur in namespace 'N'}} |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 14 | |
Richard Smith | 050d261 | 2011-10-18 02:28:33 +0000 | [diff] [blame] | 15 | template<typename T> void g(T) {} // expected-note 2{{here}} |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 16 | namespace M { |
Richard Smith | 050d261 | 2011-10-18 02:28:33 +0000 | [diff] [blame] | 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}} |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Richard Smith | 83c1929 | 2011-10-18 03:44:03 +0000 | [diff] [blame] | 21 | template inline void g<double>(double); // expected-warning {{explicit instantiation cannot be 'inline'}} |
| 22 | |
Richard Smith | 050d261 | 2011-10-18 02:28:33 +0000 | [diff] [blame] | 23 | void g() { |
Douglas Gregor | 205d044 | 2011-10-12 19:26:40 +0000 | [diff] [blame] | 24 | auto int n = 0; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}} |
Richard Smith | 8128549 | 2011-10-11 17:38:48 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | int n; |
| 28 | struct S { |
| 29 | char c; |
| 30 | } |
Douglas Gregor | 205d044 | 2011-10-12 19:26:40 +0000 | [diff] [blame] | 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}} |
Richard Smith | 3e4a60a | 2012-03-07 03:13:00 +0000 | [diff] [blame] | 33 | |
| 34 | #define PRIuS "uS" |
| 35 | int printf(const char *, ...); |
| 36 | typedef __typeof(sizeof(int)) size_t; |
| 37 | void h(size_t foo, size_t bar) { |
Richard Smith | 0df56f4 | 2012-03-08 02:39:21 +0000 | [diff] [blame] | 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}} |
Richard Smith | 3e4a60a | 2012-03-07 03:13:00 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Richard Smith | 0df56f4 | 2012-03-08 02:39:21 +0000 | [diff] [blame] | 41 | #define _x + 1 |
| 42 | char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}} |
Richard Smith | 5b013f5 | 2013-09-28 05:38:27 +0000 | [diff] [blame] | 43 | |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 44 | template<int ...N> int f() { // expected-warning {{C++11 extension}} |
| 45 | return (N + ...); // expected-warning {{C++1z extension}} |
| 46 | } |
| 47 | |
Richard Smith | 5b013f5 | 2013-09-28 05:38:27 +0000 | [diff] [blame] | 48 | #else |
| 49 | |
Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 50 | auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++14}} |
Richard Smith | 085a64f | 2014-06-20 19:57:12 +0000 | [diff] [blame] | 51 | static_assert(true); // expected-warning {{incompatible with C++ standards before C++1z}} |
Richard Smith | 5b013f5 | 2013-09-28 05:38:27 +0000 | [diff] [blame] | 52 | |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 53 | template<int ...N> int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++1z}} |
| 54 | |
Richard Smith | 5b013f5 | 2013-09-28 05:38:27 +0000 | [diff] [blame] | 55 | #endif |