summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-11-01 17:41:06 +0100
committerStephan Bergmann <sbergman@redhat.com>2021-11-01 19:13:23 +0100
commitd1ff9c1d650ada0049c867d76ba38890633a444c (patch)
tree737df88fff3e72c687cc68f6b54e5e9987c3c6f6 /compilerplugins
parentucb: webdav-curl: remove SerfLockStore::getLockToken() (diff)
downloadcore-d1ff9c1d650ada0049c867d76ba38890633a444c.tar.gz
core-d1ff9c1d650ada0049c867d76ba38890633a444c.zip
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>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/unusedmember.cxx30
-rw-r--r--compilerplugins/clang/unusedmember.cxx15
2 files changed, 40 insertions, 5 deletions
diff --git a/compilerplugins/clang/test/unusedmember.cxx b/compilerplugins/clang/test/unusedmember.cxx
index 00b136249aca..a495b786919e 100644
--- a/compilerplugins/clang/test/unusedmember.cxx
+++ b/compilerplugins/clang/test/unusedmember.cxx
@@ -13,15 +13,35 @@ namespace
{
struct S
{
- enum E
+ enum E1
{
- E1,
- E2
+ E11,
+ E12
+ };
+ E1 e1;
+ enum E2
+ {
+ E21,
+ E22
};
- E e;
+ 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
diff --git a/compilerplugins/clang/unusedmember.cxx b/compilerplugins/clang/unusedmember.cxx
index bfd4f591616d..8239b5ae1d8d 100644
--- a/compilerplugins/clang/unusedmember.cxx
+++ b/compilerplugins/clang/unusedmember.cxx
@@ -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))