ValueType: Handle 'auto'. First fix for #4345
This commit is contained in:
parent
d840005f06
commit
dad455c0dd
|
@ -4425,6 +4425,14 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
|
||||||
if (parent->isAssignmentOp()) {
|
if (parent->isAssignmentOp()) {
|
||||||
if (vt1)
|
if (vt1)
|
||||||
setValueType(parent, *vt1, cpp, defaultSignedness, settings);
|
setValueType(parent, *vt1, cpp, defaultSignedness, settings);
|
||||||
|
else if (cpp && Token::Match(parent->tokAt(-5), "[;{}] auto %var% ; %var% =")) {
|
||||||
|
Token *autoTok = parent->tokAt(-4);
|
||||||
|
if (autoTok->strAt(1) == parent->strAt(-1)) {
|
||||||
|
setValueType(autoTok, *vt2, cpp, defaultSignedness, settings);
|
||||||
|
setValueType(autoTok->next(), *vt2, cpp, defaultSignedness, settings);
|
||||||
|
setValueType(parent->previous(), *vt2, cpp, defaultSignedness, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4604,7 +4612,13 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
|
||||||
valuetype->type = ValueType::Type::FLOAT;
|
valuetype->type = ValueType::Type::FLOAT;
|
||||||
else if (type->str() == "double")
|
else if (type->str() == "double")
|
||||||
valuetype->type = type->isLong() ? ValueType::Type::LONGDOUBLE : ValueType::Type::DOUBLE;
|
valuetype->type = type->isLong() ? ValueType::Type::LONGDOUBLE : ValueType::Type::DOUBLE;
|
||||||
else if (!valuetype->typeScope && (type->str() == "struct" || type->str() == "enum"))
|
else if (type->str() == "auto" && type->valueType()) {
|
||||||
|
const ValueType *vt = type->valueType();
|
||||||
|
valuetype->type = vt->type;
|
||||||
|
valuetype->pointer = vt->pointer;
|
||||||
|
if (vt->sign != ValueType::Sign::UNKNOWN_SIGN)
|
||||||
|
valuetype->sign = vt->sign;
|
||||||
|
} else if (!valuetype->typeScope && (type->str() == "struct" || type->str() == "enum"))
|
||||||
valuetype->type = ValueType::Type::NONSTD;
|
valuetype->type = ValueType::Type::NONSTD;
|
||||||
else if (!valuetype->typeScope && type->type() && type->type()->classScope) {
|
else if (!valuetype->typeScope && type->type() && type->type()->classScope) {
|
||||||
valuetype->type = ValueType::Type::NONSTD;
|
valuetype->type = ValueType::Type::NONSTD;
|
||||||
|
|
|
@ -4238,6 +4238,9 @@ private:
|
||||||
ASSERT_EQUALS(true, vt.fromLibraryType("s32", &settingsUnix32));
|
ASSERT_EQUALS(true, vt.fromLibraryType("s32", &settingsUnix32));
|
||||||
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
|
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// auto variables
|
||||||
|
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "auto"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void variadic1() { // #7453
|
void variadic1() { // #7453
|
||||||
|
|
Loading…
Reference in New Issue