missingOverride: False positive with cv-ref mismatch (#1340)

This commit is contained in:
Sylvain Joubert 2018-08-17 08:42:22 +02:00 committed by Daniel Marjamäki
parent 0e70c8a916
commit 13617375df
2 changed files with 30 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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)