Kaydet (Commit) f2fb9139 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:unnecessaryoverride small improvement

when we have two definitions of the same method in a straight
inheritance path up our hierarchy, we were missing a warning

Change-Id: Ibc0f11644c7321a0d5618024860c2503665d8835
Reviewed-on: https://gerrit.libreoffice.org/58354
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 8f35503f
......@@ -148,4 +148,35 @@ public:
void f1() { Base3::f1(); }
};
// check the case where the method occurs more than once in a direct path up the class hierarchy
struct Base4
{
void f1();
};
struct Derived4_1 : public Base4
{
void f1();
};
struct Derived4_2 : public Derived4_1
{
void
f1() // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
{
Derived4_1::f1();
}
};
struct Base5_1
{
void f1();
};
struct Base5_2
{
void f1();
};
struct Derived5 : public Base5_1, public Base5_2
{
void f1() { Base5_1::f1(); } // no warning expected
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -389,7 +389,8 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
return nullptr;
}
std::vector<const CXXMethodDecl*> maSimilarMethods;
const CXXMethodDecl* similarMethod = nullptr;
CXXBasePath similarBasePath;
auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& path)
{
......@@ -438,18 +439,31 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
}
}
if (bParamsMatch)
maSimilarMethods.push_back(baseMethod);
{
// if we have already found a method directly below us in the inheritance hierarchy, just ignore this one
auto Compare = [&](CXXBasePathElement const & lhs, CXXBasePathElement const & rhs)
{
return lhs.Class == rhs.Class;
};
if (similarMethod
&& similarBasePath.size() < path.size()
&& std::equal(similarBasePath.begin(), similarBasePath.end(),
path.begin(), Compare))
break;
if (similarMethod)
return true; // short circuit the process
similarMethod = baseMethod;
similarBasePath = path;
}
}
return false;
};
CXXBasePaths aPaths;
methodDecl->getParent()->lookupInBases(BaseMatchesCallback, aPaths);
if (methodDecl->getParent()->lookupInBases(BaseMatchesCallback, aPaths))
return nullptr;
if (maSimilarMethods.size() == 1) {
return maSimilarMethods[0];
}
return nullptr;
return similarMethod;
}
......
......@@ -194,8 +194,6 @@ public:
/* new interface src537 */
void GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr=false) const;
SfxStyleSheet* GetStyleSheet() const;
// incomplete implementation:
// OutputDevice is necessary to determine HandleSize.
// If NULL the first signed on Win is used.
......
......@@ -253,11 +253,6 @@ void SdrView::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const
SdrCreateView::GetAttributes(rTargetSet, bOnlyHardAttr);
}
SfxStyleSheet* SdrView::GetStyleSheet() const
{
return SdrCreateView::GetStyleSheet();
}
SdrHitKind SdrView::PickAnything(const MouseEvent& rMEvt, SdrMouseEventKind nEventKind, SdrViewEvent& rVEvt) const
{
rVEvt.bMouseDown=nEventKind==SdrMouseEventKind::BUTTONDOWN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment