diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index c7f87c1e0..9751abf99 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -69,6 +69,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-multichar") set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-sign-compare") set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-unused-function") + # TODO: enable this warning - was added in Clang 8 + #set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wextra-semi-stmt") if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML) MESSAGE(FATAL_ERROR "Not use clang for generate code coverage. Use gcc. ") diff --git a/externals/tinyxml/CMakeLists.txt b/externals/tinyxml/CMakeLists.txt index 31cbeb36e..35ef355e7 100644 --- a/externals/tinyxml/CMakeLists.txt +++ b/externals/tinyxml/CMakeLists.txt @@ -2,11 +2,15 @@ file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") add_library(tinyxml_objs OBJECT ${srcs} ${hdrs}) +# TODO: needs to be fixed upstream if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - # TODO: needs to be fixed upstream target_compile_options(tinyxml_objs PRIVATE -Wno-suggest-attribute=format) + # TODO: enable this - was added in Clang 8 + #target_compile_options(tinyxml_objs PRIVATE -Wno-extra-semi-stmt) endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_library(tinyxml_objs_sanitized OBJECT EXCLUDE_FROM_ALL ${srcs} ${hdrs}) target_compile_options(tinyxml_objs_sanitized PRIVATE -fsanitize=address) + # TODO: enable this - was added in Clang 8 + #target_compile_options(tinyxml_objs_sanitized PRIVATE -Wno-extra-semi-stmt) endif() \ No newline at end of file diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 1678dbbe1..6ad07cd39 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -29,6 +29,11 @@ if (BUILD_GUI) target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART ) target_link_libraries(cppcheck-gui Qt5::Charts) endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # TODO: enable this - was added in Clang 8 + # Q_UNUSED() in generated code + #target_compile_options(cppcheck-gui PRIVATE -Wno-extra-semi-stmt) + endif() install(TARGETS cppcheck-gui RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) install(FILES ${qms} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index e3bee8cab..101eb1ecb 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -565,7 +565,7 @@ static bool checkBufferSize(const Token *ftok, const Library::ArgumentChecks::Mi return minsize.value <= bufferSize; case Library::ArgumentChecks::MinSize::Type::NONE: break; - }; + } return true; } diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 111ce80dc..164632a52 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -945,7 +945,7 @@ static inline T getvalue(const int test, const T value1, const T value2) return value2; case 5: return std::numeric_limits::max(); - }; + } return 0; } diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index d19bcda13..691c4d694 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -104,7 +104,7 @@ void VarInfo::print() default: status = "?"; break; - }; + } std::cout << "status=" << status << " " << "alloctype='" << it->second.type << "' " diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index fda9e6fc3..17c19bdee 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -287,7 +287,7 @@ static bool isOperatorFunction(const std::string & funcName) }; - return std::find(additionalOperators.begin(), additionalOperators.end(), funcName.substr(operatorPrefix.length())) != additionalOperators.end();; + return std::find(additionalOperators.begin(), additionalOperators.end(), funcName.substr(operatorPrefix.length())) != additionalOperators.end(); } diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 2c1d17b6c..f6bb09990 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1160,7 +1160,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() case ValueType::Type::LONGDOUBLE: check = true; break; - }; + } if (!check) continue; } @@ -1220,7 +1220,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() break; case Library::TypeCheck::suppress: continue; - }; + } } } diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 9cfb566ab..1aa43ff82 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -504,7 +504,7 @@ static bool findPath(const std::string &callId, if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue) break; continue; - }; + } path[index] = functionCall; return true; } diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index df7ecdad2..a001e0f30 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1025,7 +1025,7 @@ static int getIntBitsFromValueType(const ValueType *vt, const cppcheck::Platform return platform.long_long_bit; default: return 0; - }; + } } static ExprEngine::ValuePtr getValueRangeFromValueType(const std::string &name, const ValueType *vt, const cppcheck::Platform &platform) @@ -2041,7 +2041,7 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, err |= value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op2)); bad = "range " + invalidArgValue.op1 + "-" + invalidArgValue.op2; break; - }; + } if (err) { dataBase->addError(tok->linenr()); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 74acc576c..c7e37a962 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -616,7 +616,7 @@ static bool hasErrors(const simplecpp::OutputList &outputList) case simplecpp::Output::MISSING_HEADER: case simplecpp::Output::PORTABILITY_BACKSLASH: break; - }; + } } return false; } @@ -638,7 +638,7 @@ void Preprocessor::handleErrors(const simplecpp::OutputList& outputList, bool th case simplecpp::Output::MISSING_HEADER: case simplecpp::Output::PORTABILITY_BACKSLASH: break; - }; + } } } } @@ -780,7 +780,7 @@ void Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND: error(emptyString, 0, out.msg); break; - }; + } } } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 442e98292..254fee065 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1511,7 +1511,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() break; default: break; - }; + } if (bits > 0 && bits <= 62) { if (dimension.tok->valueType()->sign == ValueType::Sign::UNSIGNED) @@ -6213,7 +6213,7 @@ std::string ValueType::dump() const case LONGDOUBLE: ret << "valueType-type=\"long double\""; break; - }; + } switch (sign) { case Sign::UNKNOWN_SIGN: @@ -6224,7 +6224,7 @@ std::string ValueType::dump() const case Sign::UNSIGNED: ret << " valueType-sign=\"unsigned\""; break; - }; + } if (bits > 0) ret << " valueType-bits=\"" << bits << '\"'; @@ -6275,7 +6275,7 @@ MathLib::bigint ValueType::typeSize(const cppcheck::Platform &platform, bool p) return platform.sizeof_long_double; default: break; - }; + } // Unknown invalid size return 0; diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 3e671c98b..e59392dc0 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2275,7 +2275,7 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok, bool isTemplate case '^': tok->str((v1 ^ v2).str()); break; - }; + } } // Logical operations diff --git a/lib/token.h b/lib/token.h index 9a9485001..cb571093f 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1038,7 +1038,7 @@ public: const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [=](const ValueFlow::Value& value) { return value.isIntValue() && !value.isImpossible() && value.intvalue == val; }); - return it == mImpl->mValues->end() ? nullptr : &*it;; + return it == mImpl->mValues->end() ? nullptr : &*it; } const ValueFlow::Value * getMaxValue(bool condition) const { @@ -1064,7 +1064,7 @@ public: return value.isMovedValue() && !value.isImpossible() && value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable; }); - return it == mImpl->mValues->end() ? nullptr : &*it;; + return it == mImpl->mValues->end() ? nullptr : &*it; } const ValueFlow::Value * getValueLE(const MathLib::bigint val, const Settings *settings) const; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a378b78b8..94f0f0328 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3010,7 +3010,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::mapstr() == "const") { - ; // just skip "const" + // just skip "const" } else if (!hasstruct && variableId.find(tok2->str()) != variableId.end() && tok2->previous()->str() != "::") { ++typeCount; tok2 = tok2->next(); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 79f869c7d..9ab03de3c 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5494,7 +5494,7 @@ static bool isContainerSizeChanged(nonneg int varId, const Token *start, const T case Library::Container::Action::FIND: case Library::Container::Action::CHANGE_CONTENT: break; - }; + } } if (isContainerSizeChangedByFunction(tok, depth)) return true; @@ -5791,7 +5791,7 @@ static void valueFlowDynamicBufferSize(TokenList *tokenlist, SymbolDatabase *sym sizeValue = Token::getStrLength(value.tokvalue) + 1; // Add one for the null terminator } break; - }; + } if (sizeValue < 0) continue; @@ -5841,7 +5841,7 @@ static bool getMinMaxValues(const ValueType *vt, const cppcheck::Platform &platf break; default: return false; - }; + } if (bits == 1) { *minValue = 0; @@ -6056,7 +6056,7 @@ std::string ValueFlow::Value::infoString() const return "size=" + MathLib::toString(intvalue); case LIFETIME: return "lifetime=" + tokvalue->str(); - }; + } throw InternalError(nullptr, "Invalid ValueFlow Value type"); } diff --git a/test/redirect.h b/test/redirect.h index 196c157d1..88ff33837 100644 --- a/test/redirect.h +++ b/test/redirect.h @@ -81,7 +81,7 @@ private: std::streambuf *_oldCerr; }; -#define REDIRECT RedirectOutputError redir; +#define REDIRECT RedirectOutputError redir; do {} while(false) #define GET_REDIRECT_OUTPUT redir.getOutput() #define CLEAR_REDIRECT_OUTPUT redir.clearOutput() #define GET_REDIRECT_ERROUT redir.getErrout() diff --git a/test/testboost.cpp b/test/testboost.cpp index 7fabaca4a..eb161748a 100644 --- a/test/testboost.cpp +++ b/test/testboost.cpp @@ -35,7 +35,7 @@ private: settings.addEnabled("style"); settings.addEnabled("performance"); - TEST_CASE(BoostForeachContainerModification) + TEST_CASE(BoostForeachContainerModification); } void check(const char code[]) { diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 91841d1f6..bfc4d257f 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -899,7 +899,8 @@ private: std::istringstream istr(clang); \ clangimport::parseClangAstDump(&tokenizer, istr); \ const SymbolDatabase *db = tokenizer.getSymbolDatabase(); \ - ASSERT(db); + ASSERT(db); \ + do {} while(false) void symbolDatabaseEnum1() { const char clang[] = "|-NamespaceDecl 0x29ad5f8 <1.cpp:1:1, line:3:1> line:1:11 ns\n" diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 6963aa381..76a86ee7e 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -339,7 +339,7 @@ private: void defines2() { REDIRECT; const char * const argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"}; - settings.userDefines.clear();; + settings.userDefines.clear(); ASSERT(defParser.parseFromArgs(4, argv)); ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines); } diff --git a/test/testinternal.cpp b/test/testinternal.cpp index d5fe3846f..dd6c76d81 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -34,13 +34,13 @@ private: void run() OVERRIDE { settings.addEnabled("internal"); - TEST_CASE(simplePatternInTokenMatch) - TEST_CASE(complexPatternInTokenSimpleMatch) - TEST_CASE(simplePatternSquareBrackets) - TEST_CASE(simplePatternAlternatives) - TEST_CASE(missingPercentCharacter) - TEST_CASE(unknownPattern) - TEST_CASE(redundantNextPrevious) + TEST_CASE(simplePatternInTokenMatch); + TEST_CASE(complexPatternInTokenSimpleMatch); + TEST_CASE(simplePatternSquareBrackets); + TEST_CASE(simplePatternAlternatives); + TEST_CASE(missingPercentCharacter); + TEST_CASE(unknownPattern); + TEST_CASE(redundantNextPrevious); TEST_CASE(internalError); TEST_CASE(orInComplexPattern); TEST_CASE(extraWhitespace); diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 403def5dd..0e89a542f 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -42,12 +42,12 @@ private: TEST_CASE(ispositive); TEST_CASE(isFloat); TEST_CASE(isDecimalFloat); - TEST_CASE(isGreater) - TEST_CASE(isGreaterEqual) - TEST_CASE(isEqual) - TEST_CASE(isNotEqual) - TEST_CASE(isLess) - TEST_CASE(isLessEqual) + TEST_CASE(isGreater); + TEST_CASE(isGreaterEqual); + TEST_CASE(isEqual); + TEST_CASE(isNotEqual); + TEST_CASE(isLess); + TEST_CASE(isLessEqual); TEST_CASE(calculate); TEST_CASE(calculate1); TEST_CASE(typesuffix); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index fc32951fb..ea1c56505 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -179,13 +179,13 @@ private: TEST_CASE(strcat1); TEST_CASE(strcat2); - TEST_CASE(simplifyAtol) + TEST_CASE(simplifyAtol); TEST_CASE(simplifyOperator1); TEST_CASE(simplifyOperator2); - TEST_CASE(simplifyArrayAccessSyntax) - TEST_CASE(simplify_numeric_condition) + TEST_CASE(simplifyArrayAccessSyntax); + TEST_CASE(simplify_numeric_condition); TEST_CASE(simplify_condition); TEST_CASE(pointeralias1); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index fecb506e1..0fd9f9d4c 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -42,12 +42,12 @@ private: settings0.addEnabled("style"); settings2.addEnabled("style"); - TEST_CASE(simplifyTypedef1) - TEST_CASE(simplifyTypedef2) - TEST_CASE(simplifyTypedef3) - TEST_CASE(simplifyTypedef4) - TEST_CASE(simplifyTypedef5) - TEST_CASE(simplifyTypedef6) + TEST_CASE(simplifyTypedef1); + TEST_CASE(simplifyTypedef2); + TEST_CASE(simplifyTypedef3); + TEST_CASE(simplifyTypedef4); + TEST_CASE(simplifyTypedef5); + TEST_CASE(simplifyTypedef6); TEST_CASE(simplifyTypedef7); TEST_CASE(simplifyTypedef8); TEST_CASE(simplifyTypedef9); diff --git a/test/testsuite.h b/test/testsuite.h index 5339ed324..a5ec137c3 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -98,25 +98,25 @@ public: extern std::ostringstream errout; extern std::ostringstream output; -#define TEST_CASE( NAME ) if ( prepareTest(#NAME) ) { setVerbose(false); NAME(); } +#define TEST_CASE( NAME ) do { if ( prepareTest(#NAME) ) { setVerbose(false); NAME(); } } while(false) #define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, CONDITION)) return #define ASSERT_EQUALS( EXPECTED , ACTUAL ) if (!assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)) return #define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED , ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL) #define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL, TOLERANCE ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL, TOLERANCE) #define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG) -#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) { } catch (...) { assertThrowFail(__FILE__, __LINE__); } -#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } -#define ASSERT_NO_THROW( CMD ) try { CMD ; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } -#define TODO_ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; } catch (const EXCEPTION&) { } catch (...) { assertThrow(__FILE__, __LINE__); } -#define TODO_ASSERT( CONDITION ) { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } +#define ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) { } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while(false) +#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while(false) +#define ASSERT_NO_THROW( CMD ) do { try { CMD ; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while(false) +#define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD ; } catch (const EXCEPTION&) { } catch (...) { assertThrow(__FILE__, __LINE__); } } while(false) +#define TODO_ASSERT( CONDITION ) do { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } while(false) #define TODO_ASSERT_EQUALS( WANTED , CURRENT , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL) #define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; } #ifdef _WIN32 -#define LOAD_LIB_2( LIB, NAME ) { if (((LIB).load("./testrunner", "../cfg/" NAME).errorcode != Library::OK) && ((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::OK)) { complainMissingLib(NAME); return; } } +#define LOAD_LIB_2( LIB, NAME ) do { { if (((LIB).load("./testrunner", "../cfg/" NAME).errorcode != Library::OK) && ((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::OK)) { complainMissingLib(NAME); return; } } } while(false) #else -#define LOAD_LIB_2( LIB, NAME ) { if (((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::OK) && ((LIB).load("./bin/testrunner", "bin/cfg/" NAME).errorcode != Library::OK)) { complainMissingLib(NAME); return; } } +#define LOAD_LIB_2( LIB, NAME ) do { { if (((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::OK) && ((LIB).load("./bin/testrunner", "bin/cfg/" NAME).errorcode != Library::OK)) { complainMissingLib(NAME); return; } } } while(false) #endif #endif diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index eed41391b..543e19539 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -63,7 +63,7 @@ private: TEST_CASE(suppressionWithRelativePaths); // #4733 TEST_CASE(suppressingSyntaxErrors); // #7076 TEST_CASE(suppressingSyntaxErrorsInline); // #5917 - TEST_CASE(suppressingSyntaxErrorsWhileFileRead) // PR #1333 + TEST_CASE(suppressingSyntaxErrorsWhileFileRead); // PR #1333 TEST_CASE(symbol); TEST_CASE(unusedFunction); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f2af95f95..89253e633 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -43,11 +43,13 @@ struct InternalError; #define GET_SYMBOL_DB(code) \ Tokenizer tokenizer(&settings1, this); \ const SymbolDatabase *db = getSymbolDB_inner(tokenizer, code, "test.cpp"); \ - ASSERT(db); + ASSERT(db); \ + do {} while(false) #define GET_SYMBOL_DB_C(code) \ Tokenizer tokenizer(&settings1, this); \ - const SymbolDatabase *db = getSymbolDB_inner(tokenizer, code, "test.c"); + const SymbolDatabase *db = getSymbolDB_inner(tokenizer, code, "test.c"); \ + do {} while(false) class TestSymbolDatabase: public TestFixture { public: @@ -1232,7 +1234,7 @@ private: } void hasRegularFunction() { - GET_SYMBOL_DB("void func() { }\n") + GET_SYMBOL_DB("void func() { }\n"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2); @@ -1256,7 +1258,7 @@ private: } void hasRegularFunction_trailingReturnType() { - GET_SYMBOL_DB("auto func() -> int { }") + GET_SYMBOL_DB("auto func() -> int { }"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2); @@ -1280,7 +1282,7 @@ private: } void hasInlineClassFunction() { - GET_SYMBOL_DB("class Fred { void func() { } };\n") + GET_SYMBOL_DB("class Fred { void func() { } };\n"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1309,7 +1311,7 @@ private: void hasInlineClassFunction_trailingReturnType() { - GET_SYMBOL_DB("class Fred { auto func() -> int { } };") + GET_SYMBOL_DB("class Fred { auto func() -> int { } };"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1337,7 +1339,7 @@ private: } void hasMissingInlineClassFunction() { - GET_SYMBOL_DB("class Fred { void func(); };\n") + GET_SYMBOL_DB("class Fred { void func(); };\n"); // 2 scopes: Global and Class (no Function scope because there is no function implementation) ASSERT(db && db->scopeList.size() == 2); @@ -1386,7 +1388,7 @@ private: } void hasClassFunction() { - GET_SYMBOL_DB("class Fred { void func(); }; void Fred::func() { }\n") + GET_SYMBOL_DB("class Fred { void func(); }; void Fred::func() { }\n"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1436,7 +1438,7 @@ private: } void hasRegularFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("void (*func(int f))(char) { }\n") + GET_SYMBOL_DB("void (*func(int f))(char) { }\n"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2); @@ -1457,7 +1459,7 @@ private: } void hasInlineClassFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("class Fred { void (*func(int f))(char) { } };\n") + GET_SYMBOL_DB("class Fred { void (*func(int f))(char) { } };\n"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1478,7 +1480,7 @@ private: } void hasMissingInlineClassFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("class Fred { void (*func(int f))(char); };\n") + GET_SYMBOL_DB("class Fred { void (*func(int f))(char); };\n"); // 2 scopes: Global and Class (no Function scope because there is no function implementation) ASSERT(db && db->scopeList.size() == 2); @@ -1499,7 +1501,7 @@ private: } void hasClassFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("class Fred { void (*func(int f))(char); }; void (*Fred::func(int f))(char) { }\n") + GET_SYMBOL_DB("class Fred { void (*func(int f))(char); }; void (*Fred::func(int f))(char) { }\n"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1520,7 +1522,7 @@ private: } void methodWithRedundantScope() { - GET_SYMBOL_DB("class Fred { void Fred::func() {} };\n") + GET_SYMBOL_DB("class Fred { void Fred::func() {} };\n"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1672,7 +1674,7 @@ private: } void functionDeclarationTemplate() { - GET_SYMBOL_DB("std::map foo() {}") + GET_SYMBOL_DB("std::map foo() {}"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2 && findFunctionByName("foo", &db->scopeList.back())); @@ -1690,7 +1692,7 @@ private: } void functionDeclarations() { - GET_SYMBOL_DB("void foo();\nvoid foo();\nint foo(int i);\nvoid foo() {}") + GET_SYMBOL_DB("void foo();\nvoid foo();\nint foo(int i);\nvoid foo() {}"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2 && findFunctionByName("foo", &db->scopeList.back())); @@ -1813,7 +1815,7 @@ private: } void classWithFriend() { - GET_SYMBOL_DB("class Foo {}; class Bar1 { friend class Foo; }; class Bar2 { friend Foo; };") + GET_SYMBOL_DB("class Foo {}; class Bar1 { friend class Foo; }; class Bar2 { friend Foo; };"); // 3 scopes: Global, 3 classes ASSERT(db && db->scopeList.size() == 4); if (db) { @@ -1833,7 +1835,7 @@ private: void parseFunctionCorrect() { // ticket 3188 - "if" statement parsed as function - GET_SYMBOL_DB("void func(i) int i; { if (i == 1) return; }\n") + GET_SYMBOL_DB("void func(i) int i; { if (i == 1) return; }\n"); ASSERT(db != nullptr); // 3 scopes: Global, function, if @@ -1846,7 +1848,7 @@ private: void parseFunctionDeclarationCorrect() { GET_SYMBOL_DB("void func();\n" "int bar() {}\n" - "void func() {}") + "void func() {}"); ASSERT_EQUALS(3, db->findScopeByName("func")->bodyStart->linenr()); } @@ -1860,7 +1862,7 @@ private: } void hasGlobalVariables1() { - GET_SYMBOL_DB("int i;\n") + GET_SYMBOL_DB("int i;\n"); ASSERT(db && db->scopeList.size() == 1); if (db && db->scopeList.size() == 1) { @@ -1875,7 +1877,7 @@ private: } void hasGlobalVariables2() { - GET_SYMBOL_DB("int array[2][2];\n") + GET_SYMBOL_DB("int array[2][2];\n"); ASSERT(db && db->scopeList.size() == 1); if (db && db->scopeList.size() == 1) { @@ -1890,7 +1892,7 @@ private: } void hasGlobalVariables3() { - GET_SYMBOL_DB("int array[2][2] = { { 0, 0 }, { 0, 0 } };\n") + GET_SYMBOL_DB("int array[2][2] = { { 0, 0 }, { 0, 0 } };\n"); ASSERT(db && db->scopeList.size() == 1); if (db && db->scopeList.size() == 1) { @@ -5281,7 +5283,7 @@ private: " power.nodeResults().size();\n" " assert(power.nodeResults().size()==ground.nodeResults().size());\n" " }\n" - "};") + "};"); const Token *callfunc = Token::findsimplematch(tokenizer.tokens(), "power . nodeResults ( ) . size ( ) ;"); ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(true, db != nullptr); // not null @@ -6060,9 +6062,11 @@ private: ASSERT_EQUALS((int)ValueType::MatchResult::NOMATCH, (int)ValueType::matchParameter(&vt_const_float_pointer, &vt_long_long)); } -#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \ +#define FUNC(x) do { \ + const Function *x = findFunctionByName(#x, &db->scopeList.front()); \ ASSERT_EQUALS(true, x != nullptr); \ - if (x) ASSERT_EQUALS(true, x->isNoExcept()); + if (x) ASSERT_EQUALS(true, x->isNoExcept()); \ + } while(false) void noexceptFunction1() { GET_SYMBOL_DB("void func1() noexcept;\n" @@ -6091,9 +6095,11 @@ private: } } -#define CLASS_FUNC(x, y, z) const Function *x = findFunctionByName(#x, y); \ +#define CLASS_FUNC(x, y, z) do { \ + const Function *x = findFunctionByName(#x, y); \ ASSERT_EQUALS(true, x != nullptr); \ - if (x) ASSERT_EQUALS(z, x->isNoExcept()); + if (x) ASSERT_EQUALS(z, x->isNoExcept()); \ + } while(false) void noexceptFunction3() { GET_SYMBOL_DB("struct Fred {\n" @@ -6159,9 +6165,11 @@ private: } } -#define FUNC_THROW(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \ +#define FUNC_THROW(x) do { \ + const Function *x = findFunctionByName(#x, &db->scopeList.front()); \ ASSERT_EQUALS(true, x != nullptr); \ - if (x) ASSERT_EQUALS(true, x->isThrow()); + if (x) ASSERT_EQUALS(true, x->isThrow()); \ + } while(false) void throwFunction1() { GET_SYMBOL_DB("void func1() throw();\n" @@ -6179,9 +6187,11 @@ private: } } -#define CLASS_FUNC_THROW(x, y) const Function *x = findFunctionByName(#x, y); \ +#define CLASS_FUNC_THROW(x, y) do { \ + const Function *x = findFunctionByName(#x, y); \ ASSERT_EQUALS(true, x != nullptr); \ - if (x) ASSERT_EQUALS(true, x->isThrow()); + if (x) ASSERT_EQUALS(true, x->isThrow()); \ + } while(false) void throwFunction2() { GET_SYMBOL_DB("struct Fred {\n" " void func1() throw();\n" diff --git a/test/testtoken.cpp b/test/testtoken.cpp index cd64d507e..120c0ec8f 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -92,13 +92,13 @@ private: TEST_CASE(literals); TEST_CASE(operators); - TEST_CASE(updateProperties) - TEST_CASE(isNameGuarantees1) - TEST_CASE(isNameGuarantees2) - TEST_CASE(isNameGuarantees3) - TEST_CASE(isNameGuarantees4) - TEST_CASE(isNameGuarantees5) - TEST_CASE(isNameGuarantees6) + TEST_CASE(updateProperties); + TEST_CASE(isNameGuarantees1); + TEST_CASE(isNameGuarantees2); + TEST_CASE(isNameGuarantees3); + TEST_CASE(isNameGuarantees4); + TEST_CASE(isNameGuarantees5); + TEST_CASE(isNameGuarantees6); TEST_CASE(canFindMatchingBracketsNeedsOpen); TEST_CASE(canFindMatchingBracketsInnerPair); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 544557681..4787fb26e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3652,7 +3652,7 @@ private: const char code5[] = "const void * volatile p = NULL;"; const char res5[] = "const void * volatile p ; p = NULL ;"; - ASSERT_EQUALS(res5, tokenizeAndStringify(code5));; + ASSERT_EQUALS(res5, tokenizeAndStringify(code5)); } void vardecl5() { @@ -8016,9 +8016,9 @@ private: ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() try { }"), InternalError, "syntax error: keyword 'try' is not allowed in global scope"); // before if|for|while|switch - ASSERT_NO_THROW(tokenizeAndStringify("void f() { do switch (a) {} while (1); }")) + ASSERT_NO_THROW(tokenizeAndStringify("void f() { do switch (a) {} while (1); }")); ASSERT_NO_THROW(tokenizeAndStringify("void f() { label: switch (a) {} }")); - ASSERT_NO_THROW(tokenizeAndStringify("void f() { UNKNOWN_MACRO if (a) {} }")) + ASSERT_NO_THROW(tokenizeAndStringify("void f() { UNKNOWN_MACRO if (a) {} }")); ASSERT_NO_THROW(tokenizeAndStringify("void f() { []() -> int * {}; }")); ASSERT_NO_THROW(tokenizeAndStringify("void f() { const char* var = \"1\" \"2\"; }")); @@ -8057,13 +8057,13 @@ private: " typename U,\n" " typename std::enable_if<\n" " std::is_convertible{}>::type* = nullptr>\n" - "void foo(U x);\n")) + "void foo(U x);\n")); ASSERT_NO_THROW(tokenizeAndStringify( "template\n" "T f(const T a, const T b) {\n" " return a < b ? b : a;\n" - "}\n")) + "}\n")); ASSERT_NO_THROW(tokenizeAndStringify( "template\n" @@ -8071,7 +8071,7 @@ private: " T f(const T a, const T b) {\n" " return a < b ? b : a;\n" " }\n" - "};\n")) + "};\n")); ASSERT_NO_THROW(tokenizeAndStringify( "const int a = 1;\n" @@ -8079,7 +8079,7 @@ private: "template\n" "struct A {\n" " int x = a < b ? b : a;" - "};\n")) + "};\n")); } @@ -8097,7 +8097,7 @@ private: " bool h = f::h;\n" "};\n" "template using j = typename e::g;\n" - "}\n")) + "}\n")); ASSERT_NO_THROW(tokenizeAndStringify( "template struct a {\n" @@ -8106,7 +8106,7 @@ private: "void f() {\n" " a<> b;\n" " b.a<>::c();\n" - "}\n")) + "}\n")); // #9138 ASSERT_NO_THROW(tokenizeAndStringify( @@ -8115,7 +8115,7 @@ private: "template c d;\n" "template <> struct a {\n" "template constexpr auto g() { d<0 || e::f>; return 0; }\n" - "};\n")) + "};\n")); // #9144 ASSERT_NO_THROW(tokenizeAndStringify( @@ -8128,14 +8128,14 @@ private: "namespace d = boost;\n" "using d::c;\n" "template struct e {};\n" - "static_assert(sizeof(e<>) == sizeof(e, c, int>), \"\");\n")) + "static_assert(sizeof(e<>) == sizeof(e, c, int>), \"\");\n")); // #9146 ASSERT_NO_THROW(tokenizeAndStringify( "template struct a;\n" "template using c = typename a::e;\n" "template struct f;\n" - "template using g = typename f>::e;\n")) + "template using g = typename f>::e;\n")); // #9153 ASSERT_NO_THROW(tokenizeAndStringify( @@ -8151,7 +8151,7 @@ private: "template struct f;\n" "}\n" "template using g = b::f>;\n" - "}\n")) + "}\n")); // #9154 ASSERT_NO_THROW(tokenizeAndStringify( @@ -8172,7 +8172,7 @@ private: "template struct s;\n" "template