Skip to content
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

[Clang] Fix handling of placeholder variables name in init captures #107055

Merged
merged 2 commits into from
Sep 3, 2024
Merged
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
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ Bug Fixes to C++ Support
- Template parameter names are considered in the name lookup of out-of-line class template
specialization right before its declaration context. (#GH64082)
- Fixed a constraint comparison bug for friend declarations. (#GH78101)
- Fix handling of ``_`` as the name of a lambda's init capture variable. (#GH107024)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Sema/SemaLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,6 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,

if (C->Init.isUsable()) {
addInitCapture(LSI, cast<VarDecl>(Var), C->Kind == LCK_ByRef);
PushOnScopeChains(Var, CurScope, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, 2 is a duplicate of 1, but 3 is necessary because that constitutes a lambda body scope.

} else {
TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef
: TryCapture_ExplicitByVal;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void LookupResult::resolveKind() {

// For non-type declarations, check for a prior lookup result naming this
// canonical declaration.
if (!D->isPlaceholderVar(getSema().getLangOpts()) && !ExistingI) {
if (!ExistingI) {
auto UniqueResult = Unique.insert(std::make_pair(D, I));
if (!UniqueResult.second) {
// We've seen this entity before.
Expand Down
6 changes: 4 additions & 2 deletions clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ void f() {

void lambda() {
(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 4{{placeholder declared here}}
// expected-note 2{{placeholder declared here}}
(void)_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
};

{
int _ = 12;
(void)[_ = 0]{}; // no warning (different scope)
(void)[_ = 0]{ return _;}; // no warning (different scope)
}

auto GH107024 = [_ = 42]() { return _; }();
}

namespace global_var {
Expand Down
Loading