parent
3508464c6d
commit
c0bd9f8bbd
|
@ -2468,8 +2468,9 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
|
||||||
auto hasOverloadedMemberAccess = [](const Token* end, const Scope* scope) -> bool {
|
auto hasOverloadedMemberAccess = [](const Token* end, const Scope* scope) -> bool {
|
||||||
if (!end || !scope || !Token::simpleMatch(end->astParent(), "."))
|
if (!end || !scope || !Token::simpleMatch(end->astParent(), "."))
|
||||||
return false;
|
return false;
|
||||||
auto it = std::find_if(scope->functionList.begin(), scope->functionList.end(), [](const Function& f) {
|
const std::string op = "operator" + end->astParent()->originalName();
|
||||||
return f.isConst() && f.name() == "operator.";
|
auto it = std::find_if(scope->functionList.begin(), scope->functionList.end(), [&op](const Function& f) {
|
||||||
|
return f.isConst() && f.name() == op;
|
||||||
});
|
});
|
||||||
if (it == scope->functionList.end() || !it->retType || !it->retType->classScope)
|
if (it == scope->functionList.end() || !it->retType || !it->retType->classScope)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4396,8 +4396,7 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType
|
||||||
// check for matching return parameters
|
// check for matching return parameters
|
||||||
while (!Token::Match(temp1, "virtual|public:|private:|protected:|{|}|;")) {
|
while (!Token::Match(temp1, "virtual|public:|private:|protected:|{|}|;")) {
|
||||||
if (temp1->str() != temp2->str() &&
|
if (temp1->str() != temp2->str() &&
|
||||||
!(temp1->str() == derivedFromType->name() &&
|
!(temp1->type() && temp2->type() && temp2->type()->isDerivedFrom(temp1->type()->name()))) {
|
||||||
temp2->str() == baseType->name())) {
|
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9778,7 +9778,7 @@ void Tokenizer::simplifyOperatorName()
|
||||||
if (par->str() == "," && !op.empty())
|
if (par->str() == "," && !op.empty())
|
||||||
break;
|
break;
|
||||||
if (!(Token::Match(par, "<|>") && !op.empty())) {
|
if (!(Token::Match(par, "<|>") && !op.empty())) {
|
||||||
op += par->str();
|
op += par->str() == "." ? par->originalName() : par->str();
|
||||||
par = par->next();
|
par = par->next();
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -692,6 +692,17 @@ private:
|
||||||
" T() : S::T() {}\n"
|
" T() : S::T() {}\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkDuplInheritedMembers("struct S {};\n" // #11827
|
||||||
|
"struct SPtr {\n"
|
||||||
|
" virtual S* operator->() const { return p; }\n"
|
||||||
|
" S* p = nullptr;\n"
|
||||||
|
"};\n"
|
||||||
|
"struct T : public S {};\n"
|
||||||
|
"struct TPtr : public SPtr {\n"
|
||||||
|
" T* operator->() const { return (T*)p; }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
|
#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
|
||||||
|
@ -8349,6 +8360,18 @@ private:
|
||||||
" friend T f();\n"
|
" friend T f();\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkOverride("struct S {};\n" // #11827
|
||||||
|
"struct SPtr {\n"
|
||||||
|
" virtual S* operator->() const { return p; }\n"
|
||||||
|
" S* p = nullptr;\n"
|
||||||
|
"};\n"
|
||||||
|
"struct T : public S {};\n"
|
||||||
|
"struct TPtr : public SPtr {\n"
|
||||||
|
" T* operator->() const { return (T*)p; }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier.\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void overrideCVRefQualifiers() {
|
void overrideCVRefQualifiers() {
|
||||||
|
|
|
@ -4950,7 +4950,7 @@ private:
|
||||||
const char code[] = "void f() {"
|
const char code[] = "void f() {"
|
||||||
"static_cast<ScToken*>(xResult.operator->())->GetMatrix();"
|
"static_cast<ScToken*>(xResult.operator->())->GetMatrix();"
|
||||||
"}";
|
"}";
|
||||||
const char result[] = "void f ( ) { static_cast < ScToken * > ( xResult . operator. ( ) ) . GetMatrix ( ) ; }";
|
const char result[] = "void f ( ) { static_cast < ScToken * > ( xResult . operator-> ( ) ) . GetMatrix ( ) ; }";
|
||||||
ASSERT_EQUALS(result, tokenizeAndStringify(code));
|
ASSERT_EQUALS(result, tokenizeAndStringify(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue