Skip to content

Commit 8290ce0

Browse files
committed
[Clang] Fix handling of placeholder variables name in init captures (#107055)
We were incorrectly not deduplicating results when looking up `_` which, for a lambda init capture, would result in an ambiguous lookup. The same bug caused some diagnostic notes to be emitted twice. Fixes #107024
1 parent 327ca6c commit 8290ce0

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ Bug Fixes to C++ Support
11221122
- Fixed a crash-on-invalid bug involving extraneous template parameter with concept substitution. (#GH73885)
11231123
- Fixed assertion failure by skipping the analysis of an invalid field declaration. (#GH99868)
11241124
- Fix an issue with dependent source location expressions (#GH106428), (#GH81155), (#GH80210), (#GH85373)
1125+
- Fix handling of ``_`` as the name of a lambda's init capture variable. (#GH107024)
11251126

11261127

11271128
Bug Fixes to AST Handling

clang/lib/Sema/SemaLambda.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,6 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
13181318

13191319
if (C->Init.isUsable()) {
13201320
addInitCapture(LSI, cast<VarDecl>(Var), C->Kind == LCK_ByRef);
1321-
PushOnScopeChains(Var, CurScope, false);
13221321
} else {
13231322
TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef
13241323
: TryCapture_ExplicitByVal;

clang/lib/Sema/SemaLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void LookupResult::resolveKind() {
570570

571571
// For non-type declarations, check for a prior lookup result naming this
572572
// canonical declaration.
573-
if (!D->isPlaceholderVar(getSema().getLangOpts()) && !ExistingI) {
573+
if (!ExistingI) {
574574
auto UniqueResult = Unique.insert(std::make_pair(D, I));
575575
if (!UniqueResult.second) {
576576
// We've seen this entity before.

clang/test/SemaCXX/cxx2c-placeholder-vars.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ void f() {
5050

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

5757
{
5858
int _ = 12;
59-
(void)[_ = 0]{}; // no warning (different scope)
59+
(void)[_ = 0]{ return _;}; // no warning (different scope)
6060
}
61+
62+
auto GH107024 = [_ = 42]() { return _; }();
6163
}
6264

6365
namespace global_var {

0 commit comments

Comments
 (0)