-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Sema] Check nullness of captured type before use #72230
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: Qiu Chaofan (ecnelises) ChangesFixes #72198 Full diff: https://github.com/llvm/llvm-project/pull/72230.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5b0c4439fd1710c..cb7383ea8790f67 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19773,6 +19773,8 @@ bool Sema::tryCaptureVariable(
// declcontext can either capture the variable or have already captured
// the variable.
CaptureType = Var->getType();
+ if (CaptureType.isNull())
+ return true;
DeclRefType = CaptureType.getNonReferenceType();
bool Nested = false;
bool Explicit = (Kind != TryCapture_Implicit);
diff --git a/clang/test/SemaCXX/lambda-invalid-capture.cpp b/clang/test/SemaCXX/lambda-invalid-capture.cpp
index 236753871d7018b..b77a844cfbbda50 100644
--- a/clang/test/SemaCXX/lambda-invalid-capture.cpp
+++ b/clang/test/SemaCXX/lambda-invalid-capture.cpp
@@ -23,3 +23,9 @@ int pr43080(int i) { // expected-note {{declared here}}
i; // expected-error {{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
}();
}
+
+void pr72198() {
+ int [_, b] = {0, 0}; // expected-error{{decomposition declaration cannot be declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} \
+ expected-error{{excess elements in scalar initializer}}
+ [b]{}; // expected-warning{{expression result unused}}
+}
|
Could you please explain why the |
int [_, b] = {0, 0}; // expected-error{{decomposition declaration cannot be declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} \ | ||
expected-error{{excess elements in scalar initializer}} | ||
[b]{}; // expected-warning{{expression result unused}} |
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.
int [_, b] = {0, 0}; // expected-error{{decomposition declaration cannot be declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} \ | |
expected-error{{excess elements in scalar initializer}} | |
[b]{}; // expected-warning{{expression result unused}} | |
int [_, b] = {0, 0}; // expected-error {{decomposition declaration cannot be declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} \ | |
expected-error {{excess elements in scalar initializer}} | |
[b]{}; // expected-warning {{expression result unused}} |
@@ -19773,6 +19773,8 @@ bool Sema::tryCaptureVariable( | |||
// declcontext can either capture the variable or have already captured | |||
// the variable. | |||
CaptureType = Var->getType(); | |||
if (CaptureType.isNull()) |
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.
I am not sure this is the right fix. I think by the time we are here we should have caught any errors. I made a comment in the bug report describing my alternative.
Abandon in favor of #72428 |
No description provided.