Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ Improvements to Clang's diagnostics

- Clang now diagnoses missing return value in functions containing ``if consteval`` (#GH116485).

- Clang now omits shadowing warnings for parameter names in explicit object member functions (#GH95707).

Improvements to Clang's time-trace
----------------------------------

Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8264,11 +8264,14 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
DeclContext *NewDC = D->getDeclContext();

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

if (!MD->getType().isNull() && MD->isExplicitObjectMemberFunction())
return;
}
// Fields shadowed by constructor parameters are a special case. Usually
// the constructor initializes the field with the parameter.
if (isa<CXXConstructorDecl>(NewDC))
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/cxx2b-warn-shadow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2b -Wshadow-all %s

namespace GH95707 {
struct Foo {
int a; // expected-note {{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) { };
}
};
} // namespace GH95707
Loading