llvm-project
54 строки · 2.4 Кб
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 -Wpre-c++23-compat %s
2// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
3
4void looks_like_decltype_auto() {
5decltype(auto(42)) b = 42; // cxx20-error {{'auto' not allowed here}} \
6cxx23-warning {{'auto' as a functional-style cast is incompatible with C++ standards before C++23}}
7decltype(long *) a = 42; // expected-error {{expected '(' for function-style cast or type construction}} \
8expected-error {{expected expression}}
9decltype(auto *) a = 42; // expected-error {{expected '(' for function-style cast or type construction}} \
10expected-error {{expected expression}}
11decltype(auto()) c = 42; // cxx23-error {{initializer for functional-style cast to 'auto' is empty}} \
12cxx20-error {{'auto' not allowed here}}
13}
14
15struct looks_like_declaration {
16int 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{
32S operator()();
33S* operator->();
34int N;
35int M;
36} s; // expected-note {{here}}
37
38void test() {
39auto(s)()->N; // cxx23-warning {{expression result unused}} \
40// cxx23-warning {{before C++23}} \
41// cxx20-error {{unknown type name 'N'}}
42auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
43}
44
45void test_paren() {
46int a = (auto(0)); // cxx23-warning {{before C++23}} \
47// cxx20-error {{expected expression}} \
48// cxx20-error {{expected ')'}} \
49// cxx20-note {{to match this '('}}
50int 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