1 // RUN: %clang_cc1 -std=c++23 -verify %s
3 void test_consteval() {
4 if consteval ({(void)1;}); // expected-error {{expected { after consteval}}
5 if consteval (void) 0; // expected-error {{expected { after consteval}}
8 } else (void)0; // expected-error {{expected { after else}}
40 if consteval
[[likely
]] { // expected-warning {{attribute 'likely' has no effect when annotating an 'if consteval' statement}}\
41 // expected-note 2{{annotating the 'if consteval' statement here}}
45 else [[unlikely
]] { // expected-warning {{attribute 'unlikely' has no effect when annotating an 'if consteval' statement}}
51 void test_consteval_jumps() {
52 if consteval
{ // expected-note 4{{jump enters controlled statement of consteval if}}
54 goto b
; // expected-error {{cannot jump from this goto statement to its label}}
58 goto a
; // expected-error {{cannot jump from this goto statement to its label}}
61 goto a
; // expected-error {{cannot jump from this goto statement to its label}}
62 goto b
; // expected-error {{cannot jump from this goto statement to its label}}
65 void test_consteval_switch() {
68 if consteval
{ // expected-note 2{{jump enters controlled statement of consteval if}}
69 case 1:; // expected-error {{cannot jump from switch statement to this case label}}
70 default:; // expected-error {{cannot jump from switch statement to this case label}}
75 if consteval
{ // expected-note 2{{jump enters controlled statement of consteval if}}
77 case 2:; // expected-error {{cannot jump from switch statement to this case label}}
78 default:; // expected-error {{cannot jump from switch statement to this case label}}
83 consteval
int f(int i
) { return i
; }
84 constexpr int g(int i
) {
91 static_assert(g(10) == 10);
93 constexpr int h(int i
) { // expected-note {{declared here}}
95 return f(i
); // expected-error {{call to consteval function 'f' is not a constant expression}}\
96 // expected-note {{cannot be used in a constant expression}}
101 consteval
void warn_in_consteval() {
102 if consteval
{ // expected-warning {{consteval if is always true in an immediate context}}
103 if consteval
{} // expected-warning {{consteval if is always true in an immediate context}}
107 constexpr void warn_in_consteval2() {
109 if consteval
{} // expected-warning {{consteval if is always true in an immediate context}}
113 auto y
= []() consteval
{
114 if consteval
{ // expected-warning {{consteval if is always true in an immediate context}}
115 if consteval
{} // expected-warning {{consteval if is always true in an immediate context}}
119 namespace test_transform
{
122 n
.foo
; //expected-error {{no member named}}
128 n
.foo
; //expected-error {{no member named}}
136 constexpr int g(auto n
) {
140 n
.foo
; //expected-error {{no member named}}
146 n
.foo
; //expected-error {{no member named}}
154 f(S
{}); //expected-note {{in instantiation}}
155 g(S
{}); //expected-note {{in instantiation}}