summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-12-29 20:15:30 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-12-29 21:03:22 +0100
commit667236e600d4c23af5ecd92f33c9fa0f57edb167 (patch)
treeb8e66c501c7d01ee34800dc1c40e2d7920f7822b
parent1c5b481a52c296d1c3b93d8ae740143e44b1df6f (diff)
loplugin:unnecessaryoverride fix for changing access
Change-Id: I61b908999be7d94eed0c421125f8e1fc07e3c2db Reviewed-on: https://gerrit.libreoffice.org/47182 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/test/unnecessaryoverride.cxx13
-rw-r--r--compilerplugins/clang/unnecessaryoverride.cxx7
2 files changed, 19 insertions, 1 deletions
diff --git a/compilerplugins/clang/test/unnecessaryoverride.cxx b/compilerplugins/clang/test/unnecessaryoverride.cxx
index 7caeab3b7cec..7941263e2cec 100644
--- a/compilerplugins/clang/test/unnecessaryoverride.cxx
+++ b/compilerplugins/clang/test/unnecessaryoverride.cxx
@@ -135,4 +135,17 @@ struct Derived2 : Base2
}
};
+class Base3
+{
+public:
+ void f1();
+};
+
+class Derived3 : protected Base3
+{
+public:
+ // effectively changing access from protected to public
+ void f1() { Base3::f1(); }
+};
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/unnecessaryoverride.cxx b/compilerplugins/clang/unnecessaryoverride.cxx
index f912e43009bb..c5e483816383 100644
--- a/compilerplugins/clang/unnecessaryoverride.cxx
+++ b/compilerplugins/clang/unnecessaryoverride.cxx
@@ -391,7 +391,7 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
std::vector<const CXXMethodDecl*> maSimilarMethods;
- auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& )
+ auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& path)
{
if (cxxBaseSpecifier->getAccessSpecifier() != AS_public && cxxBaseSpecifier->getAccessSpecifier() != AS_protected)
return false;
@@ -404,6 +404,11 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
return false;
for (const CXXMethodDecl* baseMethod : baseCXXRecordDecl->methods())
{
+ auto effectiveBaseMethodAccess = baseMethod->getAccess();
+ if (effectiveBaseMethodAccess == AS_public && path.Access == AS_protected)
+ effectiveBaseMethodAccess = AS_protected;
+ if (effectiveBaseMethodAccess != methodDecl->getAccess())
+ continue;
if (!baseMethod->getDeclName().isIdentifier() || methodDecl->getName() != baseMethod->getName()) {
continue;
}