loplugin:unusedmember: Work around more cases not marking an enum as referenced

...similar to the "For some reason..." workaround already present in
VisitElaboratedTypeLoc.  (Thanks to mst for finding this.)

Change-Id: Ic682e8290efa64093d3c4a831dfb4d23091b6056
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124559
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2021-11-01 17:41:06 +01:00
parent 34f5a5a5e4
commit d1ff9c1d65
2 changed files with 40 additions and 5 deletions

View File

@ -13,15 +13,35 @@ namespace
{
struct S
{
enum E
enum E1
{
E1,
E2
E11,
E12
};
E e;
E1 e1;
enum E2
{
E21,
E22
};
E2 e2; // expected-error {{unused class member [loplugin:unusedmember]}}
enum E3
{
E31,
E32
} e3;
enum E4
{
E41,
E42
} e4; // expected-error {{unused class member [loplugin:unusedmember]}}
};
}
void f(S s) { (void)s.e; }
void f(S s)
{
(void)s.e1;
(void)s.e3;
}
}
namespace ElaboratedEnum

View File

@ -94,6 +94,21 @@ public:
#endif
bool VisitDeclaratorDecl(DeclaratorDecl const* decl)
{
// For declarations like
//
// enum E { ... } e;
//
// it may be that the declaration of E is not marked as referenced even though the
// declaration of e clearly references it:
if (auto const t = decl->getType()->getAs<EnumType>())
{
deferred_.erase(t->getDecl());
}
return true;
}
bool VisitCXXRecordDecl(CXXRecordDecl const* decl) //TODO: non-CXX RecordDecl?
{
if (ignoreLocation(decl))