diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 49464e457da68..0c12219b27b04 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -564,6 +564,8 @@ Improvements to Clang's diagnostics - Clang now correctly recognises code after a call to a ``[[noreturn]]`` constructor as unreachable (#GH63009). +- Clang now omits shadowing warnings for parameter names in explicit object member functions (#GH95707). + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index be570f3a1829d..223a532df41d9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -8264,11 +8264,14 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, DeclContext *NewDC = D->getDeclContext(); if (FieldDecl *FD = dyn_cast(ShadowedDecl)) { - // Fields are not shadowed by variables in C++ static methods. - if (CXXMethodDecl *MD = dyn_cast(NewDC)) + if (CXXMethodDecl *MD = dyn_cast(NewDC)) { + // Fields are not shadowed by variables in C++ static methods. if (MD->isStatic()) return; + if (!MD->getParent()->isLambda() && MD->isExplicitObjectMemberFunction()) + return; + } // Fields shadowed by constructor parameters are a special case. Usually // the constructor initializes the field with the parameter. if (isa(NewDC)) diff --git a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp new file mode 100644 index 0000000000000..76866c4269474 --- /dev/null +++ b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2b -Wshadow-all %s + +namespace GH95707 { +struct Foo { + int a; // expected-note 2 {{previous declaration is here}} + + void f1(this auto &self, int a) { self.a = a; } + void f2(int a) { } // expected-warning {{declaration shadows a field of 'GH95707::Foo'}} + void f3() { + (void)[&](this auto &self, int a) { }; // expected-warning {{declaration shadows a field of 'GH95707::Foo'}} + } +}; +} // namespace GH95707