[Libreoffice-commits] core.git: compilerplugins/clang
Noel Grandin
noel.grandin at collabora.co.uk
Fri Dec 29 20:03:47 UTC 2017
compilerplugins/clang/test/unnecessaryoverride.cxx | 13 +++++++++++++
compilerplugins/clang/unnecessaryoverride.cxx | 7 ++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
New commits:
commit 667236e600d4c23af5ecd92f33c9fa0f57edb167
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Fri Dec 29 20:15:30 2017 +0200
loplugin:unnecessaryoverride fix for changing access
Change-Id: I61b908999be7d94eed0c421125f8e1fc07e3c2db
Reviewed-on: https://gerrit.libreoffice.org/47182
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
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;
}
More information about the Libreoffice-commits
mailing list