[PATCH] D153296: [AST] Stop evaluate constant expression if the condition expression which in switch statement contains errors
Yurong via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 22 19:34:32 PDT 2023
yronglin added inline comments.
================
Comment at: clang/lib/AST/ExprConstant.cpp:4893
+ // Stop evaluate if E is a RecoveryExpr.
+ if (isa<RecoveryExpr>(E))
+ return false;
----------------
yronglin wrote:
> erichkeane wrote:
> > I'd probably suggest `E->containsErrors()` instead, to cover cases where we're not the 'root' of a recovery expr? So something like:
> >
> > `switch(func_call(unknown_value))`
> >
> > should create a dependent call expr, but would still contain errors.
> Thanks! Use `E->containsErrors()` and added into release note.
Seems check error inside `EvaluateDependentExpr` will missing diagnostic messages.
This case was introduced in D84637
```
constexpr int test5() { // expected-error {{constexpr function never produce}}
for (;; a++); // expected-error {{use of undeclared identifier}} \
expected-note {{constexpr evaluation hit maximum step limit; possible infinite loop?}}
return 1;
}
```
```
./main.cpp:2:11: error: use of undeclared identifier 'a'
2 | for (;; a++); // expected-error {{use of undeclared identifier}} \
| ^
1 error generated.
```
But I think the `infinite loop` diagnostic is unnecessary, should we update the test case? WDYT?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153296/new/
https://reviews.llvm.org/D153296
More information about the cfe-commits
mailing list