-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang][ExprConstant] Bail out on invalid lambda capture inits #138832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesFixes #138824 Full diff: https://github.com/llvm/llvm-project/pull/138832.diff 3 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index ae6574cf99159..32ec917effdc7 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2932,6 +2932,10 @@ bool Compiler<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
// record with their initializers.
for (const Record::Field &F : R->fields()) {
const Expr *Init = *CaptureInitIt;
+
+ if (Init->containsErrors())
+ return false;
+
++CaptureInitIt;
if (!Init)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5950f461e4b2..500d43accb082 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11038,7 +11038,7 @@ bool RecordExprEvaluator::VisitLambdaExpr(const LambdaExpr *E) {
// If there is no initializer, either this is a VLA or an error has
// occurred.
- if (!CurFieldInit)
+ if (!CurFieldInit || CurFieldInit->containsErrors())
return Error(E);
LValue Subobject = This;
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index dc8f4bf1666ee..0a135654fab18 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2598,3 +2598,12 @@ void foo() {
constexpr S s[2] = { }; // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
}
}
+
+namespace DoubleCapture {
+ int DC() {
+ int a = 1000;
+ static auto f =
+ [a, &a] { // expected-error {{'a' can appear only once in a capture list}}
+ };
+ }
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing changelog entry. Otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The summary could use improvement for the the git log something along the lines of "fix entailed checking the capture init did not contain errors"
Fixes #138824