Value-dependent ConstantExprs are not meant to be evaluated.
There is an assert in Expr::EvaluateAsConstantExpr that ensures this condition.
But before this patch the method was called without prior check.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The assert that I mentioned in the summary: https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L14969
(Although asserts are deleted in release builds, one can check the violation by llvm::errs() << isValueDependent() << "\n"; in the method)
I think I have found the right place to check the condition, right after creating the ConstantExpr object.
P.S. If this review is eventually approved, kindly please merge the commit on my behalf =) As I don't have merge access. My name is Evgeny Shulgin and email is izaronplatz@gmail.com. Sorry for inconvenience!
This looks like the right fix to me but I would prefer @aaron.ballman or @erichkeane to have the final say.
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
16820–16823 | I'd say something like / Value-dependent constant expressionS should not be immediately |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
16820–16823 | Sure, thanks! I'm bad at writing comments =) |
1 nit, but otherwise I'm happy with this.
clang/test/SemaCXX/cxx2a-consteval.cpp | ||
---|---|---|
616 | A quick comment on this test as to why it has no diagnostics would be nice. |
A friendly ping =) Seems like I don't have write access, so unfortunately I have to ask people to merge commits on my behalf. Let me copy-paste the usual comment of my reviews:
P.S. If this review is eventually approved, kindly please merge the commit on my behalf =) As I don't have merge access. My name is Evgeny Shulgin and email is izaronplatz@gmail.com. Sorry for inconvenience!
I'd say something like
/ Value-dependent constant expressionS should not be immediately
evaluated until they are instantiated.