From 13617375df9466e16177062387390f0f1620e967 Mon Sep 17 00:00:00 2001 From: Sylvain Joubert Date: Fri, 17 Aug 2018 08:42:22 +0200 Subject: [PATCH] missingOverride: False positive with cv-ref mismatch (#1340) --- lib/symboldatabase.cpp | 12 +++++++++++- test/testclass.cpp | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 24e242ac5..a584191c9 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3203,7 +3203,17 @@ const Function * Function::getOverridenFunctionRecursive(const ::Type* baseType, } // check for matching function parameters - if (match && argsMatch(baseType->classScope, func->argDef, argDef, emptyString, 0)) { + match = match && argsMatch(baseType->classScope, func->argDef, argDef, emptyString, 0); + + // check for matching cv-ref qualifiers + match = match + && isConst() == func->isConst() + && isVolatile() == func->isVolatile() + && hasRvalRefQualifier() == func->hasRvalRefQualifier() + && hasLvalRefQualifier() == func->hasLvalRefQualifier(); + + // it's a match + if (match) { return func; } } diff --git a/test/testclass.cpp b/test/testclass.cpp index 32114e6e4..d29efe926 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -214,6 +214,7 @@ private: TEST_CASE(unsafeClassDivZero); TEST_CASE(override1); + TEST_CASE(overrideCVRefQualifiers); } void checkCopyCtorAndEqOperator(const char code[]) { @@ -6827,6 +6828,24 @@ private: "class Derived : Base { virtual void f() final; };"); ASSERT_EQUALS("", errout.str()); } + + void overrideCVRefQualifiers() { + checkOverride("class Base { virtual void f(); };\n" + "class Derived : Base { void f() const; }"); + ASSERT_EQUALS("", errout.str()); + + checkOverride("class Base { virtual void f(); };\n" + "class Derived : Base { void f() volatile; }"); + ASSERT_EQUALS("", errout.str()); + + checkOverride("class Base { virtual void f(); };\n" + "class Derived : Base { void f() &; }"); + ASSERT_EQUALS("", errout.str()); + + checkOverride("class Base { virtual void f(); };\n" + "class Derived : Base { void f() &&; }"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestClass)