brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 4f20cf5 Raw
68 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++20-compat-pedantic -verify %s2// RUN: %clang_cc1 -fsyntax-only -std=c++20 -pedantic -verify %s3 4struct A { // expected-note 0+{{candidate}}5  A() = default; // expected-note 0+{{candidate}}6  int x, y;7};8A a1 = {1, 2};9#if __cplusplus <= 201703L10  // expected-warning@-2 {{aggregate initialization of type 'A' with user-declared constructors is incompatible with C++20}}11#else12  // expected-error@-4 {{no matching constructor}}13#endif14A a2 = {};15 16struct B : A { A a; };17B b1 = {{}, {}}; // ok18B b2 = {1, 2, 3, 4};19#if __cplusplus <= 201703L20  // expected-warning@-2 2{{aggregate initialization of type 'A' with user-declared constructors is incompatible with C++20}}21#else22  // expected-error@-4 2{{no viable conversion from 'int' to 'A'}}23#endif24 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.27struct string { string(const char*); }; // expected-note 0+{{candidate}}28char u8arr[] = u8"hello";29const char *u8ptr = "wo" u8"rld";30string u8str = u8"test" u8"test";31#if __cplusplus <= 201703L32// 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#else36// expected-error@-7 {{cannot initialize a variable of type 'const char *' with an lvalue of type 'const char8_t[6]'}}37// expected-error@-7 {{no viable conversion from 'const char8_t[9]' to 'string'}}38#endif39 40template<bool b>41struct C {42  explicit(C)(int);43};44#if __cplusplus <= 201703L45// expected-warning@-3 {{this expression will be parsed as explicit(bool) in C++20}}46#if defined(__cpp_conditional_explicit)47#error "the feature test macro __cpp_conditional_explicit isn't correct"48#endif49#else50// expected-error@-8 {{does not refer to a value}}51// expected-error@-9 {{expected member name or ';'}}52// expected-error@-10 {{expected ')'}}53// expected-note@-12 {{declared here}}54// expected-note@-12 {{to match this '('}}55#if !defined(__cpp_conditional_explicit) || __cpp_conditional_explicit != 201806L56#error "the feature test macro __cpp_conditional_explicit isn't correct"57#endif58#endif59 60auto l = []() consteval {};61int consteval();62#if __cplusplus <= 201703L63// expected-warning@-3 {{'consteval' is a keyword in C++20}}64// expected-error@-4 {{expected body of lambda expression}}65#else66// expected-error@-5 {{expected unqualified-id}}67#endif68