brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 9e0277e Raw
55 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 -Wpre-c++23-compat %s2// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s3 4void looks_like_decltype_auto() {5  decltype(auto(42)) b = 42; // cxx20-error {{'auto' not allowed here}} \6                                cxx23-warning {{'auto' as a functional-style cast is incompatible with C++ standards before C++23}}7  decltype(long *) a = 42;   // expected-error {{expected '(' for function-style cast or type construction}} \8                                expected-error {{expected expression}}9  decltype(auto *) a = 42;   // expected-error {{expected '(' for function-style cast or type construction}} \10                                expected-error {{expected expression}}11  decltype(auto()) c = 42;   // cxx23-error {{initializer for functional-style cast to 'auto' is empty}} \12                                cxx20-error {{'auto' not allowed here}}13}14 15struct looks_like_declaration {16  int n;17} a;18 19using T = looks_like_declaration *;20void f() { T(&a)->n = 1; }21void g() { auto(&a)->n = 0; } // cxx23-warning {{before C++23}} \22                              // cxx20-error {{declaration of variable 'a' with deduced type 'auto (&)' requires an initializer}} \23                              // cxx20-error {{expected ';' at end of declaration}}24void h() { auto{&a}->n = 0; } // cxx23-warning {{before C++23}} \25                              // cxx20-error {{expected unqualified-id}} \26                              // cxx20-error {{expected expression}}27 28void e(auto (*p)(int y) -> decltype(y)) {}29 30struct M;31struct S{32    S operator()();33    S* operator->();34    int N;35    int M;36} s; // expected-note {{here}}37 38void test() {39    auto(s)()->N; // cxx23-warning {{expression result unused}} \40                  // cxx23-warning {{before C++23}} \41                  // cxx20-error {{unknown type name 'N'}}42    auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}43}44 45void test_paren() {46    int a = (auto(0)); // cxx23-warning {{before C++23}} \47                       // cxx20-error {{expected expression}} \48                       // cxx20-error {{expected ')'}} \49                       // cxx20-note  {{to match this '('}}50    int b = (auto{0}); // cxx23-warning {{before C++23}} \51                       // cxx20-error {{expected expression}} \52                       // cxx20-error {{expected ')'}} \53                       // cxx20-note  {{to match this '('}}54}55