CheckOther: Use Variable::valueType() instead of Variable::typeStartToken
This commit is contained in:
parent
ee335e5151
commit
2a8296879c
|
@ -1425,11 +1425,7 @@ void CheckOther::checkPassByReference()
|
|||
|
||||
bool inconclusive = false;
|
||||
|
||||
const Token* const tok = var->typeStartToken();
|
||||
if (var->isStlStringType()) {
|
||||
;
|
||||
} else if (var->isStlType() && Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::") && !Token::Match(tok->tokAt(2), "initializer_list|weak_ptr|auto_ptr|unique_ptr|shared_ptr|function|pair")) {
|
||||
;
|
||||
if (var->valueType()->type == ValueType::Type::CONTAINER) {
|
||||
} else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class.
|
||||
// Ensure that it is a large object.
|
||||
if (!var->type()->classScope)
|
||||
|
@ -1444,7 +1440,7 @@ void CheckOther::checkPassByReference()
|
|||
|
||||
const bool isConst = var->isConst();
|
||||
if (isConst) {
|
||||
passedByValueError(tok, var->name(), inconclusive);
|
||||
passedByValueError(var->nameToken(), var->name(), inconclusive);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1453,7 +1449,7 @@ void CheckOther::checkPassByReference()
|
|||
continue;
|
||||
|
||||
if (canBeConst(var)) {
|
||||
passedByValueError(tok, var->name(), inconclusive);
|
||||
passedByValueError(var->nameToken(), var->name(), inconclusive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -904,17 +904,21 @@ const Library::Container* Library::detectContainer(const Token* typeStart, bool
|
|||
if (container.startPattern.empty())
|
||||
continue;
|
||||
|
||||
if (Token::Match(typeStart, container.startPattern.c_str())) {
|
||||
if (!iterator && container.endPattern.empty()) // If endPattern is undefined, it will always match, but itEndPattern has to be defined.
|
||||
return &container;
|
||||
if (!endsWith(container.startPattern, '<')) {
|
||||
if (!Token::Match(typeStart, (container.startPattern + " !!::").c_str()))
|
||||
continue;
|
||||
} else if (!Token::Match(typeStart, (container.startPattern + " !!::").c_str()))
|
||||
continue;
|
||||
|
||||
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
|
||||
if (tok->link()) {
|
||||
const std::string& endPattern = iterator ? container.itEndPattern : container.endPattern;
|
||||
if (Token::Match(tok->link(), endPattern.c_str()))
|
||||
return &container;
|
||||
break;
|
||||
}
|
||||
if (!iterator && container.endPattern.empty()) // If endPattern is undefined, it will always match, but itEndPattern has to be defined.
|
||||
return &container;
|
||||
|
||||
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
|
||||
if (tok->link()) {
|
||||
const std::string& endPattern = iterator ? container.itEndPattern : container.endPattern;
|
||||
if (Token::Match(tok->link(), endPattern.c_str()))
|
||||
return &container;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,6 +148,7 @@ private:
|
|||
|
||||
TEST_CASE(VariableValueType1);
|
||||
TEST_CASE(VariableValueType2);
|
||||
TEST_CASE(VariableValueType3);
|
||||
|
||||
TEST_CASE(findVariableType1);
|
||||
TEST_CASE(findVariableType2);
|
||||
|
@ -808,6 +809,14 @@ private:
|
|||
ASSERT(x->valueType()->isIntegral());
|
||||
}
|
||||
|
||||
void VariableValueType3() {
|
||||
GET_SYMBOL_DB("void f(std::string::size_type x);\n");
|
||||
const Variable* x = db->getVariableFromVarId(1);
|
||||
ASSERT_EQUALS("x", x->name());
|
||||
// TODO: Configure std::string::size_type somehow.
|
||||
TODO_ASSERT_EQUALS(ValueType::Type::LONGLONG, ValueType::Type::UNKNOWN_TYPE, x->valueType()->type);
|
||||
}
|
||||
|
||||
void findVariableType1() {
|
||||
GET_SYMBOL_DB("class A {\n"
|
||||
"public:\n"
|
||||
|
|
Loading…
Reference in New Issue