Richard Smith | 79c88c3 | 2018-09-26 19:00:16 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++2a-compat-pedantic -verify %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -std=c++2a -pedantic -verify %s |
| 3 | |
| 4 | struct A { // expected-note 0+{{candidate}} |
| 5 | A() = default; // expected-note 0+{{candidate}} |
| 6 | int x, y; |
| 7 | }; |
| 8 | A a1 = {1, 2}; |
| 9 | #if __cplusplus <= 201703L |
| 10 | // expected-warning@-2 {{aggregate initialization of type 'A' with user-declared constructors is incompatible with C++2a}} |
| 11 | #else |
| 12 | // expected-error@-4 {{no matching constructor}} |
| 13 | #endif |
| 14 | A a2 = {}; |
| 15 | |
| 16 | struct B : A { A a; }; |
| 17 | B b1 = {{}, {}}; // ok |
| 18 | B b2 = {1, 2, 3, 4}; |
| 19 | #if __cplusplus <= 201703L |
| 20 | // expected-warning@-2 2{{aggregate initialization of type 'A' with user-declared constructors is incompatible with C++2a}} |
| 21 | #else |
| 22 | // expected-error@-4 2{{no viable conversion from 'int' to 'A'}} |
| 23 | #endif |
Richard Smith | 28ddb91 | 2018-11-14 21:04:34 +0000 | [diff] [blame] | 24 | |
| 25 | // Essentially any use of a u8 string literal in C++<=17 is broken by C++20. |
| 26 | // Just warn on all such string literals. |
| 27 | struct string { string(const char*); }; // expected-note 0+{{candidate}} |
| 28 | char u8arr[] = u8"hello"; |
| 29 | const char *u8ptr = "wo" u8"rld"; |
| 30 | string u8str = u8"test" u8"test"; |
| 31 | #if __cplusplus <= 201703L |
| 32 | // expected-warning@-4 {{type of UTF-8 string literal will change}} expected-note@-4 {{remove 'u8' prefix}} |
| 33 | // expected-warning@-4 {{type of UTF-8 string literal will change}} expected-note@-4 {{remove 'u8' prefix}} |
| 34 | // expected-warning@-4 {{type of UTF-8 string literal will change}} expected-note@-4 {{remove 'u8' prefix}} |
| 35 | #else |
| 36 | // expected-error@-8 {{ISO C++20 does not permit initialization of char array with UTF-8 string literal}} |
| 37 | // expected-error@-8 {{cannot initialize a variable of type 'const char *' with an lvalue of type 'const char8_t [6]'}} |
| 38 | // expected-error@-8 {{no viable conversion from 'const char8_t [9]' to 'string'}} |
| 39 | #endif |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 40 | |
| 41 | template<bool b> |
| 42 | struct C { |
| 43 | explicit(C)(int); |
| 44 | }; |
| 45 | #if __cplusplus <= 201703L |
| 46 | // expected-warning@-3 {{this expression will be parsed as explicit(bool) in C++2a}} |
| 47 | #if defined(__cpp_conditional_explicit) |
| 48 | #error "the feature test macro __cpp_conditional_explicit isn't correct" |
| 49 | #endif |
| 50 | #else |
| 51 | // expected-error@-8 {{does not refer to a value}} |
| 52 | // expected-error@-9 {{expected member name or ';'}} |
| 53 | // expected-error@-10 {{expected ')'}} |
| 54 | // expected-note@-12 {{declared here}} |
| 55 | // expected-note@-12 {{to match this '('}} |
| 56 | #if !defined(__cpp_conditional_explicit) || __cpp_conditional_explicit != 201806L |
| 57 | #error "the feature test macro __cpp_conditional_explicit isn't correct" |
| 58 | #endif |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 59 | #endif |
| 60 | |
| 61 | auto l = []() consteval {}; |
| 62 | int consteval(); |
| 63 | #if __cplusplus <= 201703L |
| 64 | // expected-warning@-3 {{'consteval' is a keyword in C++2a}} |
| 65 | // expected-error@-4 {{expected body of lambda expression}} |
| 66 | #else |
| 67 | // expected-error@-5 {{expected unqualified-id}} |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 68 | #endif |