mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 19:56:38 +00:00
[Clang] Skip shadow warnings for enum constants in distinct class scopes (#115656)
Fixes #62588
This commit is contained in:
parent
43f84e7937
commit
738a047ed6
@ -537,6 +537,8 @@ Improvements to Clang's diagnostics
|
||||
|
||||
- Improved diagnostic message for ``__builtin_bit_cast`` size mismatch (#GH115870).
|
||||
|
||||
- Clang now omits shadow warnings for enum constants in separate class scopes (#GH62588).
|
||||
|
||||
Improvements to Clang's time-trace
|
||||
----------------------------------
|
||||
|
||||
|
@ -8350,9 +8350,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
|
||||
@ -8363,7 +8369,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.
|
||||
|
@ -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…
x
Reference in New Issue
Block a user