Skip to content
Merged
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ Bug Fixes in This Version
- Fixed a failed assertion with empty filename arguments in ``__has_embed``. (#GH159898)
- Fixed a failed assertion with empty filename in ``#embed`` directive. (#GH162951)
- Fixed a crash triggered by unterminated ``__has_embed``. (#GH162953)
- Fixed false-positive shadow diagnostics for lambdas in explicit object member functions. (#GH163731)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8492,12 +8492,13 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
DeclContext *NewDC = D->getDeclContext();

if (FieldDecl *FD = dyn_cast<FieldDecl>(ShadowedDecl)) {
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewDC)) {
if (CXXMethodDecl *MD =
dyn_cast<CXXMethodDecl>(getFunctionLevelDeclContext())) {
// Fields are not shadowed by variables in C++ static methods.
if (MD->isStatic())
return;

if (!MD->getParent()->isLambda() && MD->isExplicitObjectMemberFunction())
if (MD->isExplicitObjectMemberFunction())
return;
}
// Fields shadowed by constructor parameters are a special case. Usually
Expand Down
26 changes: 26 additions & 0 deletions clang/test/SemaCXX/cxx2b-warn-shadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ struct Foo {
}
};
} // namespace GH95707

namespace GH163731 {
struct S1 {
int a;
void m(this S1 &self) {
auto lambda = [](int a) { return a; };
}
};

struct S2 {
int a;
void m(this S2 &self) {
int a = 1; // expected-note {{previous declaration is here}}
auto lambda = [](int a) { // expected-warning {{declaration shadows a local variable}}
return a;
};
}
};

struct S3 {
int a;
void m(this S3 &self) {
auto lambda = [self](int a) { return a + self.a; };
}
};
}