diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index c35227ea4..e35db70a9 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -957,7 +957,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == ImplicitCastExpr) { Token *expr = children[0]->createTokens(tokenList); - if (!expr->valueType()) + if (!expr->valueType() || contains(mExtTokens, "")) setValueType(expr); return expr; } diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index b052d617b..a823fe187 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -112,6 +112,7 @@ private: TEST_CASE(valueFlow2); TEST_CASE(valueType1); + TEST_CASE(valueType2); } std::string parse(const char clang[]) { @@ -1110,6 +1111,19 @@ private: ASSERT(!!tok->valueType()); ASSERT_EQUALS("bool", tok->valueType()->str()); } + + void valueType2() { + const char clang[] = "`-VarDecl 0xc9eda0 <1.cpp:2:1, col:17> col:13 s 'const char *' cinit\n" + " `-ImplicitCastExpr 0xc9eef0 'const char *' \n" + " `-StringLiteral 0xc9eed0 'const char [6]' lvalue \"hello\"\n"; + + GET_SYMBOL_DB(clang); + + const Token *tok = Token::findsimplematch(tokenizer.tokens(), "\"hello\""); + ASSERT(!!tok); + ASSERT(!!tok->valueType()); + ASSERT_EQUALS("const signed char *", tok->valueType()->str()); + } }; REGISTER_TEST(TestClangImport)