Handle auto * const (#4994)
* Handle auto as first token * Set varid when initialized by function * Fix TODO from #11444 * Fix function parsing * Add parentheses * Format * Handle auto * const * Fix test on different platforms * simpleMatch * simpleMatch
This commit is contained in:
parent
ad464c4feb
commit
5a4e43760e
|
@ -6202,6 +6202,8 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
autoTok = var1Tok->previous();
|
autoTok = var1Tok->previous();
|
||||||
else if (Token::Match(var1Tok->tokAt(-2), "auto *|&|&&"))
|
else if (Token::Match(var1Tok->tokAt(-2), "auto *|&|&&"))
|
||||||
autoTok = var1Tok->tokAt(-2);
|
autoTok = var1Tok->tokAt(-2);
|
||||||
|
else if (Token::simpleMatch(var1Tok->tokAt(-3), "auto * const"))
|
||||||
|
autoTok = var1Tok->tokAt(-3);
|
||||||
if (autoTok) {
|
if (autoTok) {
|
||||||
ValueType vt(*vt2);
|
ValueType vt(*vt2);
|
||||||
if (vt.constness & (1 << vt.pointer))
|
if (vt.constness & (1 << vt.pointer))
|
||||||
|
@ -6226,6 +6228,8 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
vt2_.constness |= (1 << vt2->pointer);
|
vt2_.constness |= (1 << vt2->pointer);
|
||||||
if (!Token::Match(autoTok->tokAt(1), "*|&"))
|
if (!Token::Match(autoTok->tokAt(1), "*|&"))
|
||||||
vt2_.constness = vt.constness;
|
vt2_.constness = vt.constness;
|
||||||
|
if (Token::simpleMatch(autoTok->tokAt(1), "* const"))
|
||||||
|
vt2_.constness |= (1 << vt2->pointer);
|
||||||
var->setValueType(vt2_);
|
var->setValueType(vt2_);
|
||||||
if (vt2->typeScope && vt2->typeScope->definedType) {
|
if (vt2->typeScope && vt2->typeScope->definedType) {
|
||||||
var->type(vt2->typeScope->definedType);
|
var->type(vt2->typeScope->definedType);
|
||||||
|
|
|
@ -8401,6 +8401,24 @@ private:
|
||||||
ASSERT(tok && tok->valueType());
|
ASSERT(tok && tok->valueType());
|
||||||
ASSERT_EQUALS("signed int", tok->valueType()->str());
|
ASSERT_EQUALS("signed int", tok->valueType()->str());
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
GET_SYMBOL_DB("void f(const std::string& s) {\n"
|
||||||
|
" const auto* const p = s.data();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
const Token* tok = tokenizer.tokens();
|
||||||
|
tok = Token::findsimplematch(tok, "auto");
|
||||||
|
ASSERT(tok && tok->valueType());
|
||||||
|
ASSERT_EQUALS(ValueType::CHAR, tok->valueType()->type);
|
||||||
|
ASSERT_EQUALS(1, tok->valueType()->constness);
|
||||||
|
ASSERT_EQUALS(0, tok->valueType()->pointer);
|
||||||
|
tok = Token::findsimplematch(tok, "p");
|
||||||
|
ASSERT(tok && tok->variable() && tok->variable()->valueType());
|
||||||
|
ASSERT_EQUALS(ValueType::CHAR, tok->variable()->valueType()->type);
|
||||||
|
ASSERT_EQUALS(3, tok->variable()->valueType()->constness);
|
||||||
|
ASSERT_EQUALS(1, tok->variable()->valueType()->pointer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueTypeThis() {
|
void valueTypeThis() {
|
||||||
|
|
Loading…
Reference in New Issue