-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluation
Description
For this code:
constexpr int f1() {
a: for (;;) {
break azzz;
}
return 1;
}
static_assert(f1() == 1);we currently emit:
array.cpp:102:11: error: 'break' label does not name an enclosing loop or 'switch'
102 | break azzz;
| ^
array.cpp:106:15: error: static assertion expression is not an integral constant expression
106 | static_assert(f1() == 1);
| ^~~~~~~~~
array.cpp:101:15: note: constexpr evaluation hit maximum step limit; possible infinite loop?
101 | a: for (;;) {
| ^
array.cpp:106:15: note: in call to 'f1()'
106 | static_assert(f1() == 1);
| ^~~~(No godbolt link as it doesn't work there yet)
We emit an error for the break statement, but when evaluating the function call at compile time, we completely ignore the break statement altogether. We could handle it like a regular break; which would work in this case, but not for nested loops. We should simply interrupt constant evaluation of this function completely since we have already emitted an error for it.
CC @Sirraide
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluation