diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 5f6ce13f9..4ecc4ac07 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -74,9 +74,9 @@ static bool isRefPtrArg(const Token *tok) static bool isNonReferenceArg(const Token *tok) { const Variable *var = tok->variable(); - if (var && !var->valueType()) - throw InternalError(tok, "var without valueType"); - return (var && var->isArgument() && !var->isReference() && (var->isPointer() || var->valueType()->type >= ValueType::Type::CONTAINER || var->type())); + //if (var && !var->valueType()) + // throw InternalError(tok, "var without valueType"); + return (var && var->isArgument() && !var->isReference() && (var->isPointer() || (var->valueType() && var->valueType()->type >= ValueType::Type::CONTAINER) || var->type())); } static bool isAutoVar(const Token *tok) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 8c56c6428..1e94e36b4 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -968,8 +968,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) if (nodeType == VarDecl) return createTokensVarDecl(tokenList); if (nodeType == WhileStmt) { - AstNodePtr cond = children[1]; - AstNodePtr body = children[2]; + AstNodePtr cond = children[children.size() - 2]; + AstNodePtr body = children.back(); Token *whiletok = addtoken(tokenList, "while"); Token *par1 = addtoken(tokenList, "("); par1->astOperand1(whiletok); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index bf491cf7c..02632cd2b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -253,7 +253,7 @@ unsigned int CppCheck::check(const std::string &path) if (mSettings.clang) { mErrorLogger.reportOut(std::string("Checking ") + path + "..."); - const std::string clang = Path::isCPP(path) ? "clang++" : "clang"; + const std::string clang = Path::isCPP(path) ? "clang++-9" : "clang"; const std::string temp = mSettings.buildDir + "/__temp__.c"; const std::string clangcmd = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-cmd"; const std::string clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-stderr"; diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index dd4697509..c08c93a7f 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -87,7 +87,8 @@ private: TEST_CASE(vardecl3); TEST_CASE(vardecl4); TEST_CASE(vardecl5); - TEST_CASE(whileStmt); + TEST_CASE(whileStmt1); + TEST_CASE(whileStmt2); TEST_CASE(symbolDatabaseEnum1); TEST_CASE(symbolDatabaseFunction1); @@ -818,7 +819,7 @@ private: ASSERT_EQUALS("const char *const [] sys_errlist@1 ;", parse(clang)); } - void whileStmt() { + void whileStmt1() { const char clang[] = "`-FunctionDecl 0x3d45b18 <1.c:1:1, line:3:1> line:1:6 foo 'void ()'\n" " `-CompoundStmt 0x3d45c48 \n" " `-WhileStmt 0x3d45c28 \n" @@ -830,6 +831,18 @@ private: parse(clang)); } + void whileStmt2() { + // clang 9 + const char clang[] = "`-FunctionDecl 0x1c99ac8 <1.cpp:1:1, col:27> col:6 foo 'void ()'\n" + " `-CompoundStmt 0x1c99c10 \n" + " `-WhileStmt 0x1c99bf8 \n" + " |-ImplicitCastExpr 0x1c99bd0 'bool' \n" + " | `-IntegerLiteral 0x1c99bb0 'int' 1\n" + " `-CompoundStmt 0x1c99be8 "; + ASSERT_EQUALS("void foo ( ) { while ( 1 ) { } }", parse(clang)); + } + + #define GET_SYMBOL_DB(clang) \ Settings settings; \ settings.clang = true; \