Richard Smith | 7b5a8bf | 2017-08-25 02:25:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++17 -pedantic -verify %s |
Richard Smith | 9b2c5e7 | 2018-09-28 01:16:43 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -std=c++2a -Wc++17-compat-pedantic -verify %s -Wno-defaulted-function-deleted |
Richard Smith | 7b5a8bf | 2017-08-25 02:25:07 +0000 | [diff] [blame] | 3 | |
| 4 | struct A {}; |
| 5 | int (A::*pa)() const&; |
| 6 | int use_pa = (A().*pa)(); |
| 7 | #if __cplusplus <= 201703L |
| 8 | // expected-warning@-2 {{invoking a pointer to a 'const &' member function on an rvalue is a C++2a extension}} |
| 9 | #else |
| 10 | // expected-warning@-4 {{invoking a pointer to a 'const &' member function on an rvalue is incompatible with C++ standards before C++2a}} |
| 11 | #endif |
| 12 | |
| 13 | struct B { |
| 14 | void b() { |
| 15 | (void) [=, this] {}; |
| 16 | #if __cplusplus <= 201703L |
| 17 | // expected-warning@-2 {{explicit capture of 'this' with a capture default of '=' is a C++2a extension}} |
| 18 | #else |
| 19 | // expected-warning@-4 {{explicit capture of 'this' with a capture default of '=' is incompatible with C++ standards before C++2a}} |
| 20 | #endif |
| 21 | } |
Richard Smith | 8b63344 | 2017-08-28 00:31:35 +0000 | [diff] [blame] | 22 | |
| 23 | int n : 5 = 0; |
| 24 | #if __cplusplus <= 201703L |
| 25 | // expected-warning@-2 {{default member initializer for bit-field is a C++2a extension}} |
| 26 | #else |
| 27 | // expected-warning@-4 {{default member initializer for bit-field is incompatible with C++ standards before C++2a}} |
| 28 | #endif |
Richard Smith | 7b5a8bf | 2017-08-25 02:25:07 +0000 | [diff] [blame] | 29 | }; |
Richard Smith | 864949b | 2018-09-27 22:47:04 +0000 | [diff] [blame] | 30 | |
| 31 | auto Lambda = []{}; |
| 32 | decltype(Lambda) AnotherLambda; |
| 33 | #if __cplusplus <= 201703L |
| 34 | // expected-error@-2 {{no matching constructor}} expected-note@-3 2{{candidate}} |
| 35 | #else |
| 36 | // expected-warning@-4 {{default construction of lambda is incompatible with C++ standards before C++2a}} |
| 37 | #endif |
| 38 | |
| 39 | void copy_lambda() { Lambda = Lambda; } |
| 40 | #if __cplusplus <= 201703L |
| 41 | // expected-error@-2 {{deleted}} expected-note@-10 {{lambda}} |
| 42 | #else |
| 43 | // expected-warning@-4 {{assignment of lambda is incompatible with C++ standards before C++2a}} |
| 44 | #endif |
Richard Smith | 9b2c5e7 | 2018-09-28 01:16:43 +0000 | [diff] [blame] | 45 | |
| 46 | struct DefaultDeleteWrongTypeBase { |
| 47 | DefaultDeleteWrongTypeBase(DefaultDeleteWrongTypeBase&); |
| 48 | }; |
| 49 | struct DefaultDeleteWrongType : DefaultDeleteWrongTypeBase { |
| 50 | DefaultDeleteWrongType(const DefaultDeleteWrongType&) = default; |
| 51 | #if __cplusplus <= 201703L |
| 52 | // expected-error@-2 {{a member or base requires it to be non-const}} |
| 53 | #else |
| 54 | // expected-warning@-4 {{explicitly defaulting this copy constructor with a type different from the implicit type is incompatible with C++ standards before C++2a}} |
| 55 | #endif |
| 56 | }; |
Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 57 | |
| 58 | void ForRangeInit() { |
| 59 | for (int arr[3] = {1, 2, 3}; int n : arr) {} |
| 60 | #if __cplusplus <= 201703L |
| 61 | // expected-warning@-2 {{range-based for loop initialization statements are a C++2a extension}} |
| 62 | #else |
| 63 | // expected-warning@-4 {{range-based for loop initialization statements are incompatible with C++ standards before C++2a}} |
| 64 | #endif |
| 65 | } |