diff --git a/lib/token.cpp b/lib/token.cpp index 575b1966aee..0c64222801d 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2459,7 +2459,7 @@ std::pair Token::typeDecl(const Token* tok, bool poi typeBeg = previousBeforeAstLeftmostLeaf(tok2); typeEnd = tok2; } - if (typeBeg) + if (typeBeg && typeBeg != typeEnd) result = { typeBeg->next(), typeEnd }; // handle smart pointers/iterators first } if (astIsRangeBasedForDecl(var->nameToken()) && astIsContainer(var->nameToken()->astParent()->astOperand2())) { // range-based for diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 23808237fcc..71578810017 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7990,6 +7990,12 @@ class TestValueFlow : public TestFixture { "};\n" "U u;\n"; (void)valueOfTok(code, "new"); + + code = "void f() {\n" // #14287 + " auto a = { \"1\" };\n" + " auto b = a;\n" + "}\n"; + (void)valueOfTok(code, "b"); } void valueFlowHang() {