Skip to content

[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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Collaborator

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.

return true;
DeclRefType = CaptureType.getNonReferenceType();
bool Nested = false;
bool Explicit = (Kind != TryCapture_Implicit);
Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/lambda-invalid-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Comment on lines +28 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}}

}