@@ -502,6 +502,7 @@ class TestSymbolDatabase : public TestFixture {
502502 TEST_CASE (auto16);
503503 TEST_CASE (auto17); // #11163
504504 TEST_CASE (auto18);
505+ TEST_CASE (auto19);
505506
506507 TEST_CASE (unionWithConstructor);
507508
@@ -8811,6 +8812,42 @@ class TestSymbolDatabase : public TestFixture {
88118812 TODO_ASSERT (autoTok->valueType ()->reference == Reference::LValue);
88128813 }
88138814
8815+ void auto19 () { // #11517
8816+ {
8817+ GET_SYMBOL_DB (" void f(const std::vector<void*>& v) {\n "
8818+ " for (const auto* h : v)\n "
8819+ " if (h) {}\n "
8820+ " }\n " );
8821+ ASSERT_EQUALS (3 , db->variableList ().size ());
8822+
8823+ const Variable* h = db->variableList ()[2 ];
8824+ ASSERT (h->isPointer ());
8825+ ASSERT (!h->isConst ());
8826+ const Token* varTok = Token::findsimplematch (tokenizer.tokens (), " h )" );
8827+ ASSERT (varTok && varTok->valueType ());
8828+ ASSERT_EQUALS (varTok->valueType ()->constness , 1 );
8829+ ASSERT_EQUALS (varTok->valueType ()->pointer , 1 );
8830+ }
8831+ {
8832+ GET_SYMBOL_DB (" struct B { virtual void f() {} };\n "
8833+ " struct D : B {};\n "
8834+ " void g(const std::vector<B*>& v) {\n "
8835+ " for (auto* b : v)\n "
8836+ " if (auto d = dynamic_cast<D*>(b))\n "
8837+ " d->f();\n "
8838+ " }\n " );
8839+ ASSERT_EQUALS (4 , db->variableList ().size ());
8840+
8841+ const Variable* b = db->variableList ()[2 ];
8842+ ASSERT (b->isPointer ());
8843+ ASSERT (!b->isConst ());
8844+ const Token* varTok = Token::findsimplematch (tokenizer.tokens (), " b )" );
8845+ ASSERT (varTok && varTok->valueType ());
8846+ ASSERT_EQUALS (varTok->valueType ()->constness , 0 );
8847+ ASSERT_EQUALS (varTok->valueType ()->pointer , 1 );
8848+ }
8849+ }
8850+
88148851 void unionWithConstructor () {
88158852 GET_SYMBOL_DB (" union Fred {\n "
88168853 " Fred(int x) : i(x) { }\n "
0 commit comments