diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 983df21f7..462db07d5 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -860,7 +860,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == ImplicitCastExpr) { Token *expr = children[0]->createTokens(tokenList); - setValueType(expr); + if (!expr->valueType()) + setValueType(expr); return expr; } if (nodeType == InitListExpr) { diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 05ba90b1f..dbf8b9f8a 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -98,6 +98,8 @@ private: TEST_CASE(valueFlow1); TEST_CASE(valueFlow2); + + TEST_CASE(valueType1); } std::string parse(const char clang[]) { @@ -979,6 +981,23 @@ private: ASSERT(tok->hasKnownIntValue()); ASSERT_EQUALS(10, tok->getKnownIntValue()); } + + void valueType1() { + const char clang[] = "`-FunctionDecl 0x32438c0 line:5:6 foo 'a::b (a::b)'\n" + " |-ParmVarDecl 0x32437b0 col:15 used i 'a::b':'long'\n" + " `-CompoundStmt 0x3243a60 \n" + " `-ReturnStmt 0x3243a48 \n" + " `-ImplicitCastExpr 0x2176ca8 'int' \n" + " `-ImplicitCastExpr 0x2176c90 'bool' \n" + " `-DeclRefExpr 0x2176c60 'bool' lvalue Var 0x2176bd0 'e' 'bool'\n"; + + GET_SYMBOL_DB(clang); + + const Token *tok = Token::findsimplematch(tokenizer.tokens(), "e"); + ASSERT(!!tok); + ASSERT(!!tok->valueType()); + ASSERT_EQUALS("bool", tok->valueType()->str()); + } }; REGISTER_TEST(TestClangImport)