1 // RUN: %clang_cc1 -fsyntax-only -std=c++2c -verify=expected,cxx26 %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify=expected,cxx23 %s
8 consteval
void test() { // cxx23-error{{consteval function never produces a constant expression}}
11 volatile void* c
= &t
;
12 (void)static_cast<T
*>(a
); //cxx23-note {{cast from 'void *' is not allowed in a constant expression in C++ standards before C++2c}}
13 (void)static_cast<const T
*>(a
);
14 (void)static_cast<volatile T
*>(a
);
18 (void)(volatile T
*)(a
);
20 (void)static_cast<T
*>(b
); // expected-error {{static_cast from 'const void *' to 'T *' casts away qualifiers}}
21 (void)static_cast<volatile T
*>(b
); // expected-error {{static_cast from 'const void *' to 'volatile T *' casts away qualifiers}}
22 (void)static_cast<const T
*>(b
);
23 (void)static_cast<volatile const T
*>(b
);
25 (void)static_cast<T
*>(c
); // expected-error{{static_cast from 'volatile void *' to 'T *' casts away qualifiers}}
26 (void)static_cast<volatile T
*>(c
);
27 (void)static_cast<const T
*>(b
);
28 (void)static_cast<volatile const T
*>(b
);
32 constexpr void* a
= &t
;
33 constexpr auto err1
= static_cast<int*>(a
); // expected-error{{constexpr variable 'err1' must be initialized by a constant expression}} \
34 // cxx23-note {{cast from 'void *' is not allowed in a constant expression in C++ standards before C++2c}} \
35 // cxx26-note {{cast from 'void *' is not allowed in a constant expression because the pointed object type 'T' is not similar to the target type 'int'}}
36 constexpr auto err2
= static_cast<S
*>(a
); // expected-error{{constexpr variable 'err2' must be initialized by a constant expression}} \
37 // cxx23-note {{cast from 'void *' is not allowed in a constant expression in C++ standards before C++2c}} \
38 // cxx26-note {{cast from 'void *' is not allowed in a constant expression because the pointed object type 'T' is not similar to the target type 'S'}}