Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6139,7 +6139,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
// range for loop, auto
if (vt2 &&
parent->str() == ":" &&
Token::Match(parent->astParent(), "( const| auto *|&| %var% :") &&
Token::Match(parent->astParent(), "( const| auto *|&| %var% :") && // TODO: east-const, multiple const, ref to ptr, rvalue ref
!parent->previous()->valueType() &&
Token::simpleMatch(parent->astParent()->astOperand1(), "for")) {
const bool isconst = Token::simpleMatch(parent->astParent()->next(), "const");
Expand All @@ -6152,8 +6152,14 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
setAutoTokenProperties(autoToken);
ValueType varvt(*vt2);
varvt.pointer--;
if (isconst)
varvt.constness |= 1;
if (Token::simpleMatch(autoToken->next(), "&"))
varvt.reference = Reference::LValue;
if (isconst) {
if (varvt.pointer && varvt.reference != Reference::None)
varvt.constness |= 2;
else
varvt.constness |= 1;
}
setValueType(parent->previous(), varvt);
Variable *var = const_cast<Variable *>(parent->previous()->variable());
if (var) {
Expand Down
6 changes: 5 additions & 1 deletion test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7736,7 +7736,11 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS("signed int", typeOf("; auto data = new X::Y; int x=1000; x=x/5;", "/")); // #7970
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (nothrow) int[100];", "data"));
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x"));
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto x : values); }", "x"));
ASSERT_EQUALS("const signed short &", typeOf("short values[10]; void f() { for (const auto& x : values); }", "x"));
ASSERT_EQUALS("signed short &", typeOf("short values[10]; void f() { for (auto& x : values); }", "x"));
ASSERT_EQUALS("signed int * &", typeOf("int* values[10]; void f() { for (auto& p : values); }", "p"));
ASSERT_EQUALS("signed int * const &", typeOf("int* values[10]; void f() { for (const auto& p : values); }", "p"));
ASSERT_EQUALS("const signed int", typeOf("; const auto x = 3;", "x"));
ASSERT_EQUALS("const signed int", typeOf("; constexpr auto x = 3;", "x"));
ASSERT_EQUALS("const signed int", typeOf("; const constexpr auto x = 3;", "x"));
Expand Down