Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -527,6 +527,8 @@ Improvements to Clang's diagnostics

- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073).

- Clang now omits shadow warnings for enum constants in separate class scopes (#GH62588).

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

Expand Down
11 changes: 8 additions & 3 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8328,9 +8328,15 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
return;

// Only warn about certain kinds of shadowing for class members.
if (NewDC && NewDC->isRecord()) {
if (NewDC) {
// In particular, don't warn about shadowing non-class members.
if (!OldDC->isRecord())
if (NewDC->isRecord() && !OldDC->isRecord())
return;

// Skip shadowing check if we're in a class scope, dealing with an enum
// constant in a different context.
DeclContext *ReDC = NewDC->getRedeclContext();
if (ReDC->isRecord() && isa<EnumConstantDecl>(D) && !OldDC->Equals(ReDC))
return;

// TODO: should we warn about static data members shadowing
Expand All @@ -8341,7 +8347,6 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
// shadowing context, but that's just a false negative.
}


DeclarationName Name = R.getLookupName();

// Emit warning and note.
Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaCXX/warn-shadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,17 @@ void test4() {
}

}; // namespace structured_binding_tests

namespace GH62588 {
class Outer {
public:
char *foo(); // expected-note {{previous declaration is here}} \
// expected-note {{previous definition is here}}
enum Outer_E { foo }; // expected-error {{redefinition of 'foo'}} \
// expected-warning {{declaration shadows a static data member of 'GH62588::Outer'}}
class Inner {
public:
enum Inner_E { foo }; // ok
};
};
} // namespace GH62588
Loading