fixed -Wextra-semi-stmt Clang warnings (#2553)

* fixed -Wextra-semi-stmt Clang warnings

* adjusted REDIRECT macro to require a semicolon

* testmathlib.cpp: rolled back accidental change
This commit is contained in:
Oliver Stöneberg 2020-04-21 17:27:51 +02:00 committed by GitHub
parent c60652630f
commit 1af959af2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 179 additions and 144 deletions

View File

@ -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-multichar")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-sign-compare") set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-sign-compare")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-unused-function") 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) if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
MESSAGE(FATAL_ERROR "Not use clang for generate code coverage. Use gcc. ") MESSAGE(FATAL_ERROR "Not use clang for generate code coverage. Use gcc. ")

View File

@ -2,11 +2,15 @@ file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp") file(GLOB srcs "*.cpp")
add_library(tinyxml_objs OBJECT ${srcs} ${hdrs}) add_library(tinyxml_objs OBJECT ${srcs} ${hdrs})
# TODO: needs to be fixed upstream
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# TODO: needs to be fixed upstream
target_compile_options(tinyxml_objs PRIVATE -Wno-suggest-attribute=format) 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() endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_library(tinyxml_objs_sanitized OBJECT EXCLUDE_FROM_ALL ${srcs} ${hdrs}) add_library(tinyxml_objs_sanitized OBJECT EXCLUDE_FROM_ALL ${srcs} ${hdrs})
target_compile_options(tinyxml_objs_sanitized PRIVATE -fsanitize=address) 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() endif()

View File

@ -29,6 +29,11 @@ if (BUILD_GUI)
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART ) target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART )
target_link_libraries(cppcheck-gui Qt5::Charts) target_link_libraries(cppcheck-gui Qt5::Charts)
endif() 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(TARGETS cppcheck-gui RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications)
install(FILES ${qms} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) install(FILES ${qms} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications)

View File

@ -565,7 +565,7 @@ static bool checkBufferSize(const Token *ftok, const Library::ArgumentChecks::Mi
return minsize.value <= bufferSize; return minsize.value <= bufferSize;
case Library::ArgumentChecks::MinSize::Type::NONE: case Library::ArgumentChecks::MinSize::Type::NONE:
break; break;
}; }
return true; return true;
} }

View File

@ -945,7 +945,7 @@ static inline T getvalue(const int test, const T value1, const T value2)
return value2; return value2;
case 5: case 5:
return std::numeric_limits<T>::max(); return std::numeric_limits<T>::max();
}; }
return 0; return 0;
} }

View File

@ -104,7 +104,7 @@ void VarInfo::print()
default: default:
status = "?"; status = "?";
break; break;
}; }
std::cout << "status=" << status << " " std::cout << "status=" << status << " "
<< "alloctype='" << it->second.type << "' " << "alloctype='" << it->second.type << "' "

View File

@ -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();
} }

View File

@ -1160,7 +1160,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
case ValueType::Type::LONGDOUBLE: case ValueType::Type::LONGDOUBLE:
check = true; check = true;
break; break;
}; }
if (!check) if (!check)
continue; continue;
} }
@ -1220,7 +1220,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
break; break;
case Library::TypeCheck::suppress: case Library::TypeCheck::suppress:
continue; continue;
}; }
} }
} }

View File

@ -504,7 +504,7 @@ static bool findPath(const std::string &callId,
if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue) if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue)
break; break;
continue; continue;
}; }
path[index] = functionCall; path[index] = functionCall;
return true; return true;
} }

View File

@ -1025,7 +1025,7 @@ static int getIntBitsFromValueType(const ValueType *vt, const cppcheck::Platform
return platform.long_long_bit; return platform.long_long_bit;
default: default:
return 0; return 0;
}; }
} }
static ExprEngine::ValuePtr getValueRangeFromValueType(const std::string &name, const ValueType *vt, const cppcheck::Platform &platform) 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)); err |= value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op2));
bad = "range " + invalidArgValue.op1 + "-" + invalidArgValue.op2; bad = "range " + invalidArgValue.op1 + "-" + invalidArgValue.op2;
break; break;
}; }
if (err) { if (err) {
dataBase->addError(tok->linenr()); dataBase->addError(tok->linenr());

View File

@ -616,7 +616,7 @@ static bool hasErrors(const simplecpp::OutputList &outputList)
case simplecpp::Output::MISSING_HEADER: case simplecpp::Output::MISSING_HEADER:
case simplecpp::Output::PORTABILITY_BACKSLASH: case simplecpp::Output::PORTABILITY_BACKSLASH:
break; break;
}; }
} }
return false; return false;
} }
@ -638,7 +638,7 @@ void Preprocessor::handleErrors(const simplecpp::OutputList& outputList, bool th
case simplecpp::Output::MISSING_HEADER: case simplecpp::Output::MISSING_HEADER:
case simplecpp::Output::PORTABILITY_BACKSLASH: case simplecpp::Output::PORTABILITY_BACKSLASH:
break; break;
}; }
} }
} }
} }
@ -780,7 +780,7 @@ void Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND: case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
error(emptyString, 0, out.msg); error(emptyString, 0, out.msg);
break; break;
}; }
} }
} }

View File

@ -1511,7 +1511,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
break; break;
default: default:
break; break;
}; }
if (bits > 0 && bits <= 62) { if (bits > 0 && bits <= 62) {
if (dimension.tok->valueType()->sign == ValueType::Sign::UNSIGNED) if (dimension.tok->valueType()->sign == ValueType::Sign::UNSIGNED)
@ -6213,7 +6213,7 @@ std::string ValueType::dump() const
case LONGDOUBLE: case LONGDOUBLE:
ret << "valueType-type=\"long double\""; ret << "valueType-type=\"long double\"";
break; break;
}; }
switch (sign) { switch (sign) {
case Sign::UNKNOWN_SIGN: case Sign::UNKNOWN_SIGN:
@ -6224,7 +6224,7 @@ std::string ValueType::dump() const
case Sign::UNSIGNED: case Sign::UNSIGNED:
ret << " valueType-sign=\"unsigned\""; ret << " valueType-sign=\"unsigned\"";
break; break;
}; }
if (bits > 0) if (bits > 0)
ret << " valueType-bits=\"" << bits << '\"'; ret << " valueType-bits=\"" << bits << '\"';
@ -6275,7 +6275,7 @@ MathLib::bigint ValueType::typeSize(const cppcheck::Platform &platform, bool p)
return platform.sizeof_long_double; return platform.sizeof_long_double;
default: default:
break; break;
}; }
// Unknown invalid size // Unknown invalid size
return 0; return 0;

View File

@ -2275,7 +2275,7 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok, bool isTemplate
case '^': case '^':
tok->str((v1 ^ v2).str()); tok->str((v1 ^ v2).str());
break; break;
}; }
} }
// Logical operations // Logical operations

View File

@ -1038,7 +1038,7 @@ public:
const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [=](const ValueFlow::Value& value) { 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 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 { const ValueFlow::Value * getMaxValue(bool condition) const {
@ -1064,7 +1064,7 @@ public:
return value.isMovedValue() && !value.isImpossible() && return value.isMovedValue() && !value.isImpossible() &&
value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable; 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; const ValueFlow::Value * getValueLE(const MathLib::bigint val, const Settings *settings) const;

View File

@ -3010,7 +3010,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
typeCount = 0; typeCount = 0;
singleNameCount = 0; singleNameCount = 0;
} else if (tok2->str() == "const") { } else if (tok2->str() == "const") {
; // just skip "const" // just skip "const"
} else if (!hasstruct && variableId.find(tok2->str()) != variableId.end() && tok2->previous()->str() != "::") { } else if (!hasstruct && variableId.find(tok2->str()) != variableId.end() && tok2->previous()->str() != "::") {
++typeCount; ++typeCount;
tok2 = tok2->next(); tok2 = tok2->next();

View File

@ -5494,7 +5494,7 @@ static bool isContainerSizeChanged(nonneg int varId, const Token *start, const T
case Library::Container::Action::FIND: case Library::Container::Action::FIND:
case Library::Container::Action::CHANGE_CONTENT: case Library::Container::Action::CHANGE_CONTENT:
break; break;
}; }
} }
if (isContainerSizeChangedByFunction(tok, depth)) if (isContainerSizeChangedByFunction(tok, depth))
return true; 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 sizeValue = Token::getStrLength(value.tokvalue) + 1; // Add one for the null terminator
} }
break; break;
}; }
if (sizeValue < 0) if (sizeValue < 0)
continue; continue;
@ -5841,7 +5841,7 @@ static bool getMinMaxValues(const ValueType *vt, const cppcheck::Platform &platf
break; break;
default: default:
return false; return false;
}; }
if (bits == 1) { if (bits == 1) {
*minValue = 0; *minValue = 0;
@ -6056,7 +6056,7 @@ std::string ValueFlow::Value::infoString() const
return "size=" + MathLib::toString(intvalue); return "size=" + MathLib::toString(intvalue);
case LIFETIME: case LIFETIME:
return "lifetime=" + tokvalue->str(); return "lifetime=" + tokvalue->str();
}; }
throw InternalError(nullptr, "Invalid ValueFlow Value type"); throw InternalError(nullptr, "Invalid ValueFlow Value type");
} }

View File

@ -81,7 +81,7 @@ private:
std::streambuf *_oldCerr; std::streambuf *_oldCerr;
}; };
#define REDIRECT RedirectOutputError redir; #define REDIRECT RedirectOutputError redir; do {} while(false)
#define GET_REDIRECT_OUTPUT redir.getOutput() #define GET_REDIRECT_OUTPUT redir.getOutput()
#define CLEAR_REDIRECT_OUTPUT redir.clearOutput() #define CLEAR_REDIRECT_OUTPUT redir.clearOutput()
#define GET_REDIRECT_ERROUT redir.getErrout() #define GET_REDIRECT_ERROUT redir.getErrout()

View File

@ -35,7 +35,7 @@ private:
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("performance"); settings.addEnabled("performance");
TEST_CASE(BoostForeachContainerModification) TEST_CASE(BoostForeachContainerModification);
} }
void check(const char code[]) { void check(const char code[]) {

View File

@ -899,7 +899,8 @@ private:
std::istringstream istr(clang); \ std::istringstream istr(clang); \
clangimport::parseClangAstDump(&tokenizer, istr); \ clangimport::parseClangAstDump(&tokenizer, istr); \
const SymbolDatabase *db = tokenizer.getSymbolDatabase(); \ const SymbolDatabase *db = tokenizer.getSymbolDatabase(); \
ASSERT(db); ASSERT(db); \
do {} while(false)
void symbolDatabaseEnum1() { void symbolDatabaseEnum1() {
const char clang[] = "|-NamespaceDecl 0x29ad5f8 <1.cpp:1:1, line:3:1> line:1:11 ns\n" const char clang[] = "|-NamespaceDecl 0x29ad5f8 <1.cpp:1:1, line:3:1> line:1:11 ns\n"

View File

@ -339,7 +339,7 @@ private:
void defines2() { void defines2() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"}; const char * const argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"};
settings.userDefines.clear();; settings.userDefines.clear();
ASSERT(defParser.parseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
} }

View File

@ -34,13 +34,13 @@ private:
void run() OVERRIDE { void run() OVERRIDE {
settings.addEnabled("internal"); settings.addEnabled("internal");
TEST_CASE(simplePatternInTokenMatch) TEST_CASE(simplePatternInTokenMatch);
TEST_CASE(complexPatternInTokenSimpleMatch) TEST_CASE(complexPatternInTokenSimpleMatch);
TEST_CASE(simplePatternSquareBrackets) TEST_CASE(simplePatternSquareBrackets);
TEST_CASE(simplePatternAlternatives) TEST_CASE(simplePatternAlternatives);
TEST_CASE(missingPercentCharacter) TEST_CASE(missingPercentCharacter);
TEST_CASE(unknownPattern) TEST_CASE(unknownPattern);
TEST_CASE(redundantNextPrevious) TEST_CASE(redundantNextPrevious);
TEST_CASE(internalError); TEST_CASE(internalError);
TEST_CASE(orInComplexPattern); TEST_CASE(orInComplexPattern);
TEST_CASE(extraWhitespace); TEST_CASE(extraWhitespace);

View File

@ -42,12 +42,12 @@ private:
TEST_CASE(ispositive); TEST_CASE(ispositive);
TEST_CASE(isFloat); TEST_CASE(isFloat);
TEST_CASE(isDecimalFloat); TEST_CASE(isDecimalFloat);
TEST_CASE(isGreater) TEST_CASE(isGreater);
TEST_CASE(isGreaterEqual) TEST_CASE(isGreaterEqual);
TEST_CASE(isEqual) TEST_CASE(isEqual);
TEST_CASE(isNotEqual) TEST_CASE(isNotEqual);
TEST_CASE(isLess) TEST_CASE(isLess);
TEST_CASE(isLessEqual) TEST_CASE(isLessEqual);
TEST_CASE(calculate); TEST_CASE(calculate);
TEST_CASE(calculate1); TEST_CASE(calculate1);
TEST_CASE(typesuffix); TEST_CASE(typesuffix);

View File

@ -179,13 +179,13 @@ private:
TEST_CASE(strcat1); TEST_CASE(strcat1);
TEST_CASE(strcat2); TEST_CASE(strcat2);
TEST_CASE(simplifyAtol) TEST_CASE(simplifyAtol);
TEST_CASE(simplifyOperator1); TEST_CASE(simplifyOperator1);
TEST_CASE(simplifyOperator2); TEST_CASE(simplifyOperator2);
TEST_CASE(simplifyArrayAccessSyntax) TEST_CASE(simplifyArrayAccessSyntax);
TEST_CASE(simplify_numeric_condition) TEST_CASE(simplify_numeric_condition);
TEST_CASE(simplify_condition); TEST_CASE(simplify_condition);
TEST_CASE(pointeralias1); TEST_CASE(pointeralias1);

View File

@ -42,12 +42,12 @@ private:
settings0.addEnabled("style"); settings0.addEnabled("style");
settings2.addEnabled("style"); settings2.addEnabled("style");
TEST_CASE(simplifyTypedef1) TEST_CASE(simplifyTypedef1);
TEST_CASE(simplifyTypedef2) TEST_CASE(simplifyTypedef2);
TEST_CASE(simplifyTypedef3) TEST_CASE(simplifyTypedef3);
TEST_CASE(simplifyTypedef4) TEST_CASE(simplifyTypedef4);
TEST_CASE(simplifyTypedef5) TEST_CASE(simplifyTypedef5);
TEST_CASE(simplifyTypedef6) TEST_CASE(simplifyTypedef6);
TEST_CASE(simplifyTypedef7); TEST_CASE(simplifyTypedef7);
TEST_CASE(simplifyTypedef8); TEST_CASE(simplifyTypedef8);
TEST_CASE(simplifyTypedef9); TEST_CASE(simplifyTypedef9);

View File

@ -98,25 +98,25 @@ public:
extern std::ostringstream errout; extern std::ostringstream errout;
extern std::ostringstream output; 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( CONDITION ) if (!assert_(__FILE__, __LINE__, CONDITION)) return
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) if (!assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)) 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_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_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_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( CMD, EXCEPTION ) do { try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) { } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while(false)
#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_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 ) try { CMD ; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } #define ASSERT_NO_THROW( CMD ) do { try { CMD ; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while(false)
#define TODO_ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; } catch (const EXCEPTION&) { } catch (...) { assertThrow(__FILE__, __LINE__); } #define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD ; } catch (const EXCEPTION&) { } catch (...) { assertThrow(__FILE__, __LINE__); } } while(false)
#define TODO_ASSERT( CONDITION ) { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } #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 TODO_ASSERT_EQUALS( WANTED , CURRENT , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL)
#define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) #define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; } #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; }
#ifdef _WIN32 #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 #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
#endif #endif

View File

@ -63,7 +63,7 @@ private:
TEST_CASE(suppressionWithRelativePaths); // #4733 TEST_CASE(suppressionWithRelativePaths); // #4733
TEST_CASE(suppressingSyntaxErrors); // #7076 TEST_CASE(suppressingSyntaxErrors); // #7076
TEST_CASE(suppressingSyntaxErrorsInline); // #5917 TEST_CASE(suppressingSyntaxErrorsInline); // #5917
TEST_CASE(suppressingSyntaxErrorsWhileFileRead) // PR #1333 TEST_CASE(suppressingSyntaxErrorsWhileFileRead); // PR #1333
TEST_CASE(symbol); TEST_CASE(symbol);
TEST_CASE(unusedFunction); TEST_CASE(unusedFunction);

View File

@ -43,11 +43,13 @@ struct InternalError;
#define GET_SYMBOL_DB(code) \ #define GET_SYMBOL_DB(code) \
Tokenizer tokenizer(&settings1, this); \ Tokenizer tokenizer(&settings1, this); \
const SymbolDatabase *db = getSymbolDB_inner(tokenizer, code, "test.cpp"); \ const SymbolDatabase *db = getSymbolDB_inner(tokenizer, code, "test.cpp"); \
ASSERT(db); ASSERT(db); \
do {} while(false)
#define GET_SYMBOL_DB_C(code) \ #define GET_SYMBOL_DB_C(code) \
Tokenizer tokenizer(&settings1, this); \ 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 { class TestSymbolDatabase: public TestFixture {
public: public:
@ -1232,7 +1234,7 @@ private:
} }
void hasRegularFunction() { void hasRegularFunction() {
GET_SYMBOL_DB("void func() { }\n") GET_SYMBOL_DB("void func() { }\n");
// 2 scopes: Global and Function // 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2); ASSERT(db && db->scopeList.size() == 2);
@ -1256,7 +1258,7 @@ private:
} }
void hasRegularFunction_trailingReturnType() { void hasRegularFunction_trailingReturnType() {
GET_SYMBOL_DB("auto func() -> int { }") GET_SYMBOL_DB("auto func() -> int { }");
// 2 scopes: Global and Function // 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2); ASSERT(db && db->scopeList.size() == 2);
@ -1280,7 +1282,7 @@ private:
} }
void hasInlineClassFunction() { void hasInlineClassFunction() {
GET_SYMBOL_DB("class Fred { void func() { } };\n") GET_SYMBOL_DB("class Fred { void func() { } };\n");
// 3 scopes: Global, Class, and Function // 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3); ASSERT(db && db->scopeList.size() == 3);
@ -1309,7 +1311,7 @@ private:
void hasInlineClassFunction_trailingReturnType() { 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 // 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3); ASSERT(db && db->scopeList.size() == 3);
@ -1337,7 +1339,7 @@ private:
} }
void hasMissingInlineClassFunction() { 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) // 2 scopes: Global and Class (no Function scope because there is no function implementation)
ASSERT(db && db->scopeList.size() == 2); ASSERT(db && db->scopeList.size() == 2);
@ -1386,7 +1388,7 @@ private:
} }
void hasClassFunction() { 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 // 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3); ASSERT(db && db->scopeList.size() == 3);
@ -1436,7 +1438,7 @@ private:
} }
void hasRegularFunctionReturningFunctionPointer() { 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 // 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2); ASSERT(db && db->scopeList.size() == 2);
@ -1457,7 +1459,7 @@ private:
} }
void hasInlineClassFunctionReturningFunctionPointer() { 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 // 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3); ASSERT(db && db->scopeList.size() == 3);
@ -1478,7 +1480,7 @@ private:
} }
void hasMissingInlineClassFunctionReturningFunctionPointer() { 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) // 2 scopes: Global and Class (no Function scope because there is no function implementation)
ASSERT(db && db->scopeList.size() == 2); ASSERT(db && db->scopeList.size() == 2);
@ -1499,7 +1501,7 @@ private:
} }
void hasClassFunctionReturningFunctionPointer() { 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 // 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3); ASSERT(db && db->scopeList.size() == 3);
@ -1520,7 +1522,7 @@ private:
} }
void methodWithRedundantScope() { 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 // 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3); ASSERT(db && db->scopeList.size() == 3);
@ -1672,7 +1674,7 @@ private:
} }
void functionDeclarationTemplate() { void functionDeclarationTemplate() {
GET_SYMBOL_DB("std::map<int, string> foo() {}") GET_SYMBOL_DB("std::map<int, string> foo() {}");
// 2 scopes: Global and Function // 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2 && findFunctionByName("foo", &db->scopeList.back())); ASSERT(db && db->scopeList.size() == 2 && findFunctionByName("foo", &db->scopeList.back()));
@ -1690,7 +1692,7 @@ private:
} }
void functionDeclarations() { 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 // 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2 && findFunctionByName("foo", &db->scopeList.back())); ASSERT(db && db->scopeList.size() == 2 && findFunctionByName("foo", &db->scopeList.back()));
@ -1813,7 +1815,7 @@ private:
} }
void classWithFriend() { 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 // 3 scopes: Global, 3 classes
ASSERT(db && db->scopeList.size() == 4); ASSERT(db && db->scopeList.size() == 4);
if (db) { if (db) {
@ -1833,7 +1835,7 @@ private:
void parseFunctionCorrect() { void parseFunctionCorrect() {
// ticket 3188 - "if" statement parsed as function // 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); ASSERT(db != nullptr);
// 3 scopes: Global, function, if // 3 scopes: Global, function, if
@ -1846,7 +1848,7 @@ private:
void parseFunctionDeclarationCorrect() { void parseFunctionDeclarationCorrect() {
GET_SYMBOL_DB("void func();\n" GET_SYMBOL_DB("void func();\n"
"int bar() {}\n" "int bar() {}\n"
"void func() {}") "void func() {}");
ASSERT_EQUALS(3, db->findScopeByName("func")->bodyStart->linenr()); ASSERT_EQUALS(3, db->findScopeByName("func")->bodyStart->linenr());
} }
@ -1860,7 +1862,7 @@ private:
} }
void hasGlobalVariables1() { void hasGlobalVariables1() {
GET_SYMBOL_DB("int i;\n") GET_SYMBOL_DB("int i;\n");
ASSERT(db && db->scopeList.size() == 1); ASSERT(db && db->scopeList.size() == 1);
if (db && db->scopeList.size() == 1) { if (db && db->scopeList.size() == 1) {
@ -1875,7 +1877,7 @@ private:
} }
void hasGlobalVariables2() { void hasGlobalVariables2() {
GET_SYMBOL_DB("int array[2][2];\n") GET_SYMBOL_DB("int array[2][2];\n");
ASSERT(db && db->scopeList.size() == 1); ASSERT(db && db->scopeList.size() == 1);
if (db && db->scopeList.size() == 1) { if (db && db->scopeList.size() == 1) {
@ -1890,7 +1892,7 @@ private:
} }
void hasGlobalVariables3() { 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); ASSERT(db && db->scopeList.size() == 1);
if (db && db->scopeList.size() == 1) { if (db && db->scopeList.size() == 1) {
@ -5281,7 +5283,7 @@ private:
" power.nodeResults().size();\n" " power.nodeResults().size();\n"
" assert(power.nodeResults().size()==ground.nodeResults().size());\n" " assert(power.nodeResults().size()==ground.nodeResults().size());\n"
" }\n" " }\n"
"};") "};");
const Token *callfunc = Token::findsimplematch(tokenizer.tokens(), "power . nodeResults ( ) . size ( ) ;"); const Token *callfunc = Token::findsimplematch(tokenizer.tokens(), "power . nodeResults ( ) . size ( ) ;");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS(true, db != nullptr); // not null 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)); 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); \ ASSERT_EQUALS(true, x != nullptr); \
if (x) ASSERT_EQUALS(true, x->isNoExcept()); if (x) ASSERT_EQUALS(true, x->isNoExcept()); \
} while(false)
void noexceptFunction1() { void noexceptFunction1() {
GET_SYMBOL_DB("void func1() noexcept;\n" 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); \ ASSERT_EQUALS(true, x != nullptr); \
if (x) ASSERT_EQUALS(z, x->isNoExcept()); if (x) ASSERT_EQUALS(z, x->isNoExcept()); \
} while(false)
void noexceptFunction3() { void noexceptFunction3() {
GET_SYMBOL_DB("struct Fred {\n" 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); \ ASSERT_EQUALS(true, x != nullptr); \
if (x) ASSERT_EQUALS(true, x->isThrow()); if (x) ASSERT_EQUALS(true, x->isThrow()); \
} while(false)
void throwFunction1() { void throwFunction1() {
GET_SYMBOL_DB("void func1() throw();\n" 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); \ ASSERT_EQUALS(true, x != nullptr); \
if (x) ASSERT_EQUALS(true, x->isThrow()); if (x) ASSERT_EQUALS(true, x->isThrow()); \
} while(false)
void throwFunction2() { void throwFunction2() {
GET_SYMBOL_DB("struct Fred {\n" GET_SYMBOL_DB("struct Fred {\n"
" void func1() throw();\n" " void func1() throw();\n"

View File

@ -92,13 +92,13 @@ private:
TEST_CASE(literals); TEST_CASE(literals);
TEST_CASE(operators); TEST_CASE(operators);
TEST_CASE(updateProperties) TEST_CASE(updateProperties);
TEST_CASE(isNameGuarantees1) TEST_CASE(isNameGuarantees1);
TEST_CASE(isNameGuarantees2) TEST_CASE(isNameGuarantees2);
TEST_CASE(isNameGuarantees3) TEST_CASE(isNameGuarantees3);
TEST_CASE(isNameGuarantees4) TEST_CASE(isNameGuarantees4);
TEST_CASE(isNameGuarantees5) TEST_CASE(isNameGuarantees5);
TEST_CASE(isNameGuarantees6) TEST_CASE(isNameGuarantees6);
TEST_CASE(canFindMatchingBracketsNeedsOpen); TEST_CASE(canFindMatchingBracketsNeedsOpen);
TEST_CASE(canFindMatchingBracketsInnerPair); TEST_CASE(canFindMatchingBracketsInnerPair);

View File

@ -3652,7 +3652,7 @@ private:
const char code5[] = "const void * volatile p = NULL;"; const char code5[] = "const void * volatile p = NULL;";
const char res5[] = "const void * volatile p ; p = NULL ;"; const char res5[] = "const void * volatile p ; p = NULL ;";
ASSERT_EQUALS(res5, tokenizeAndStringify(code5));; ASSERT_EQUALS(res5, tokenizeAndStringify(code5));
} }
void vardecl5() { 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"); ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() try { }"), InternalError, "syntax error: keyword 'try' is not allowed in global scope");
// before if|for|while|switch // 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() { 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() { []() -> int * {}; }"));
ASSERT_NO_THROW(tokenizeAndStringify("void f() { const char* var = \"1\" \"2\"; }")); ASSERT_NO_THROW(tokenizeAndStringify("void f() { const char* var = \"1\" \"2\"; }"));
@ -8057,13 +8057,13 @@ private:
" typename U,\n" " typename U,\n"
" typename std::enable_if<\n" " typename std::enable_if<\n"
" std::is_convertible<U, T>{}>::type* = nullptr>\n" " std::is_convertible<U, T>{}>::type* = nullptr>\n"
"void foo(U x);\n")) "void foo(U x);\n"));
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
"template<class t>\n" "template<class t>\n"
"T f(const T a, const T b) {\n" "T f(const T a, const T b) {\n"
" return a < b ? b : a;\n" " return a < b ? b : a;\n"
"}\n")) "}\n"));
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
"template<class T>\n" "template<class T>\n"
@ -8071,7 +8071,7 @@ private:
" T f(const T a, const T b) {\n" " T f(const T a, const T b) {\n"
" return a < b ? b : a;\n" " return a < b ? b : a;\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
"const int a = 1;\n" "const int a = 1;\n"
@ -8079,7 +8079,7 @@ private:
"template<class T>\n" "template<class T>\n"
"struct A {\n" "struct A {\n"
" int x = a < b ? b : a;" " int x = a < b ? b : a;"
"};\n")) "};\n"));
} }
@ -8097,7 +8097,7 @@ private:
" bool h = f::h;\n" " bool h = f::h;\n"
"};\n" "};\n"
"template <typename i> using j = typename e<i>::g;\n" "template <typename i> using j = typename e<i>::g;\n"
"}\n")) "}\n"));
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
"template <typename = void> struct a {\n" "template <typename = void> struct a {\n"
@ -8106,7 +8106,7 @@ private:
"void f() {\n" "void f() {\n"
" a<> b;\n" " a<> b;\n"
" b.a<>::c();\n" " b.a<>::c();\n"
"}\n")) "}\n"));
// #9138 // #9138
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
@ -8115,7 +8115,7 @@ private:
"template <bool b> c<b> d;\n" "template <bool b> c<b> d;\n"
"template <> struct a<int> {\n" "template <> struct a<int> {\n"
"template <typename e> constexpr auto g() { d<0 || e::f>; return 0; }\n" "template <typename e> constexpr auto g() { d<0 || e::f>; return 0; }\n"
"};\n")) "};\n"));
// #9144 // #9144
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
@ -8128,14 +8128,14 @@ private:
"namespace d = boost;\n" "namespace d = boost;\n"
"using d::c;\n" "using d::c;\n"
"template <typename...> struct e {};\n" "template <typename...> struct e {};\n"
"static_assert(sizeof(e<>) == sizeof(e<c<int>, c<int>, int>), \"\");\n")) "static_assert(sizeof(e<>) == sizeof(e<c<int>, c<int>, int>), \"\");\n"));
// #9146 // #9146
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
"template <int> struct a;\n" "template <int> struct a;\n"
"template <class, class b> using c = typename a<int{b::d}>::e;\n" "template <class, class b> using c = typename a<int{b::d}>::e;\n"
"template <class> struct f;\n" "template <class> struct f;\n"
"template <class b> using g = typename f<c<int, b>>::e;\n")) "template <class b> using g = typename f<c<int, b>>::e;\n"));
// #9153 // #9153
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
@ -8151,7 +8151,7 @@ private:
"template <class> struct f;\n" "template <class> struct f;\n"
"}\n" "}\n"
"template <class c> using g = b::f<e<int, c>>;\n" "template <class c> using g = b::f<e<int, c>>;\n"
"}\n")) "}\n"));
// #9154 // #9154
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
@ -8172,7 +8172,7 @@ private:
"template <class, class> struct s;\n" "template <class, class> struct s;\n"
"template <template <class> class t, class... w, template <class> class x,\n" "template <template <class> class t, class... w, template <class> class x,\n"
" class... u>\n" " class... u>\n"
"struct s<t<w...>, x<u...>>;\n")) "struct s<t<w...>, x<u...>>;\n"));
// #9156 // #9156
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
@ -8186,7 +8186,7 @@ private:
" template <class... ag> using ah = typename ab<h, ag..., g...>::e;\n" " template <class... ag> using ah = typename ab<h, ag..., g...>::e;\n"
"};\n" "};\n"
"template <class> struct F;\n" "template <class> struct F;\n"
"int main() { using T = void (*)(a<j<F, char[]>>); }\n")) "int main() { using T = void (*)(a<j<F, char[]>>); }\n"));
// #9340 // #9340
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
@ -8195,24 +8195,24 @@ private:
" using d = a;\n" " using d = a;\n"
" d e = {(p1)...};\n" " d e = {(p1)...};\n"
" }\n" " }\n"
"};\n")) "};\n"));
} }
void checkNamespaces() { void checkNamespaces() {
ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}")) ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}"));
} }
void checkLambdas() { void checkLambdas() {
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, &i] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, &i] {}; }"));
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i] {}; }"));
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i = std::move(i)] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i = std::move(i)] {}; }"));
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, i = std::move(i)] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, i = std::move(i)] {}; }"));
ASSERT_NO_THROW(tokenizeAndStringify("struct c {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct c {\n"
" void d() {\n" " void d() {\n"
" int a;\n" " int a;\n"
" auto b = [this, a] {};\n" " auto b = [this, a] {};\n"
" }\n" " }\n"
"};\n")) "};\n"));
// #9525 // #9525
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
@ -8222,7 +8222,7 @@ private:
" return {[] {\n" " return {[] {\n"
" if (0) {}\n" " if (0) {}\n"
" }};\n" " }};\n"
"}\n")) "}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" template <class b> a(b) {}\n" " template <class b> a(b) {}\n"
"};\n" "};\n"
@ -8231,7 +8231,7 @@ private:
" if (0) {}\n" " if (0) {}\n"
" return 0;\n" " return 0;\n"
" }};\n" " }};\n"
"}\n")) "}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" template <class b> a(b) {}\n" " template <class b> a(b) {}\n"
"};\n" "};\n"
@ -8240,14 +8240,14 @@ private:
" if (0) {}\n" " if (0) {}\n"
" return 0;\n" " return 0;\n"
" }};\n" " }};\n"
"}\n")) "}\n"));
// #0535 // #0535
ASSERT_NO_THROW(tokenizeAndStringify("template <typename, typename> struct a;\n" ASSERT_NO_THROW(tokenizeAndStringify("template <typename, typename> struct a;\n"
"template <typename, typename b> void c() {\n" "template <typename, typename b> void c() {\n"
" ([]() -> decltype(0) {\n" " ([]() -> decltype(0) {\n"
" if (a<b, decltype(0)>::d) {}\n" " if (a<b, decltype(0)>::d) {}\n"
" });\n" " });\n"
"}\n")) "}\n"));
// #9563 // #9563
ASSERT_NO_THROW(tokenizeAndStringify("template <typename> struct a;\n" ASSERT_NO_THROW(tokenizeAndStringify("template <typename> struct a;\n"
@ -8255,7 +8255,7 @@ private:
" template <typename d> a(d);\n" " template <typename d> a(d);\n"
"};\n" "};\n"
"void e(\n" "void e(\n"
" int, a<void()> f = [] {});\n")) " int, a<void()> f = [] {});\n"));
// #9644 // #9644
ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n" ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n"
@ -8263,14 +8263,14 @@ private:
" auto c = [](int d) {\n" " auto c = [](int d) {\n"
" for (char e = 0; d;) {}\n" " for (char e = 0; d;) {}\n"
" };\n" " };\n"
"}\n")) "}\n"));
// #9537 // #9537
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" template <typename b> a(b) {}\n" " template <typename b> a(b) {}\n"
"};\n" "};\n"
"a c{[] {\n" "a c{[] {\n"
" if (0) {}\n" " if (0) {}\n"
"}};\n")) "}};\n"));
} }
void checkIfCppCast() { void checkIfCppCast() {
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
@ -8284,7 +8284,7 @@ private:
" int f = 0;\n" " int f = 0;\n"
" if (!const_cast<a *>(&e)->b()) {}\n" " if (!const_cast<a *>(&e)->b()) {}\n"
" return f;\n" " return f;\n"
"}\n")) "}\n"));
} }
void checkRefQualifiers() { void checkRefQualifiers() {
@ -8293,56 +8293,56 @@ private:
" void b() && {\n" " void b() && {\n"
" if (this) {}\n" " if (this) {}\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n" ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" void b() & {\n" " void b() & {\n"
" if (this) {}\n" " if (this) {}\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n" ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" auto b() && -> void {\n" " auto b() && -> void {\n"
" if (this) {}\n" " if (this) {}\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n" ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" auto b() & -> void {\n" " auto b() & -> void {\n"
" if (this) {}\n" " if (this) {}\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n" ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" auto b(int& x) -> int& {\n" " auto b(int& x) -> int& {\n"
" if (this) {}\n" " if (this) {}\n"
" return x;\n" " return x;\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n" ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" auto b(int& x) -> int&& {\n" " auto b(int& x) -> int&& {\n"
" if (this) {}\n" " if (this) {}\n"
" return x;\n" " return x;\n"
" }\n" " }\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n" ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" auto b(int& x) && -> int& {\n" " auto b(int& x) && -> int& {\n"
" if (this) {}\n" " if (this) {}\n"
" return x;\n" " return x;\n"
" }\n" " }\n"
"};\n")) "};\n"));
// #9524 // #9524
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int* {\n" ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int* {\n"
" if (0) {}\n" " if (0) {}\n"
" return 0;\n" " return 0;\n"
"};\n")) "};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int** {\n" ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int** {\n"
" if (0) {}\n" " if (0) {}\n"
" return 0;\n" " return 0;\n"
"};\n")) "};\n"));
} }
void checkConditionBlock() { void checkConditionBlock() {
ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n" ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n"
" for (auto b : std::vector<std::vector<int>>{{}, {}}) {}\n" " for (auto b : std::vector<std::vector<int>>{{}, {}}) {}\n"
"}\n")) "}\n"));
} }
void noCrash1() { void noCrash1() {
@ -8350,7 +8350,7 @@ private:
"struct A {\n" "struct A {\n"
" A( const std::string &name = "" );\n" " A( const std::string &name = "" );\n"
"};\n" "};\n"
"A::A( const std::string &name ) { return; }\n")) "A::A( const std::string &name ) { return; }\n"));
} }
// #9007 // #9007
@ -8367,7 +8367,7 @@ private:
"};\n" "};\n"
"template <> d<int>::d(const int &, a::b, double, double);\n" "template <> d<int>::d(const int &, a::b, double, double);\n"
"template <> d<int>::d(const d &) {}\n" "template <> d<int>::d(const d &) {}\n"
"template <> d<c>::d(const d &) {}\n")) "template <> d<c>::d(const d &) {}\n"));
} }
void checkConfig(const char code[]) { void checkConfig(const char code[]) {

View File

@ -810,12 +810,14 @@ private:
ASSERT_EQUALS(1, values.back().intvalue); ASSERT_EQUALS(1, values.back().intvalue);
#define CHECK(A, B) \ #define CHECK(A, B) \
do { \
code = "void f() {\n" \ code = "void f() {\n" \
" x = sizeof(" A ");\n" \ " x = sizeof(" A ");\n" \
"}"; \ "}"; \
values = tokenValues(code,"( " A " )"); \ values = tokenValues(code,"( " A " )"); \
ASSERT_EQUALS(1U, values.size()); \ ASSERT_EQUALS(1U, values.size()); \
ASSERT_EQUALS(B, values.back().intvalue); ASSERT_EQUALS(B, values.back().intvalue);\
} while(false)
// standard types // standard types
CHECK("void *", settings.sizeof_pointer); CHECK("void *", settings.sizeof_pointer);
@ -849,13 +851,15 @@ private:
ASSERT_EQUALS(10, values.back().intvalue); ASSERT_EQUALS(10, values.back().intvalue);
#define CHECK(A, B, C, D) \ #define CHECK(A, B, C, D) \
do { \
code = "enum " A " E " B " { E0, E1 };\n" \ code = "enum " A " E " B " { E0, E1 };\n" \
"void f() {\n" \ "void f() {\n" \
" x = sizeof(" C ");\n" \ " x = sizeof(" C ");\n" \
"}"; \ "}"; \
values = tokenValues(code,"( " C " )"); \ values = tokenValues(code,"( " C " )"); \
ASSERT_EQUALS(1U, values.size()); \ ASSERT_EQUALS(1U, values.size()); \
ASSERT_EQUALS(D, values.back().intvalue); ASSERT_EQUALS(D, values.back().intvalue); \
} while(false)
// enums // enums
CHECK("", "", "E", settings.sizeof_int); CHECK("", "", "E", settings.sizeof_int);
@ -922,6 +926,7 @@ private:
#undef CHECK #undef CHECK
#define CHECK(A, B) \ #define CHECK(A, B) \
do { \
code = "enum E " A " { E0, E1 };\n" \ code = "enum E " A " { E0, E1 };\n" \
"void f() {\n" \ "void f() {\n" \
" E arrE[] = { E0, E1 };\n" \ " E arrE[] = { E0, E1 };\n" \
@ -929,7 +934,8 @@ private:
"}"; \ "}"; \
values = tokenValues(code,"( arrE )"); \ values = tokenValues(code,"( arrE )"); \
ASSERT_EQUALS(1U, values.size()); \ ASSERT_EQUALS(1U, values.size()); \
ASSERT_EQUALS(B * 2U, values.back().intvalue); ASSERT_EQUALS(B * 2U, values.back().intvalue);\
} while(false)
// enum array // enum array
CHECK("", settings.sizeof_int); CHECK("", settings.sizeof_int);
@ -955,6 +961,7 @@ private:
#undef CHECK #undef CHECK
#define CHECK(A, B) \ #define CHECK(A, B) \
do { \
code = "enum class E " A " { E0, E1 };\n" \ code = "enum class E " A " { E0, E1 };\n" \
"void f() {\n" \ "void f() {\n" \
" E arrE[] = { E::E0, E::E1 };\n" \ " E arrE[] = { E::E0, E::E1 };\n" \
@ -962,7 +969,8 @@ private:
"}"; \ "}"; \
values = tokenValues(code,"( arrE )"); \ values = tokenValues(code,"( arrE )"); \
ASSERT_EQUALS(1U, values.size()); \ ASSERT_EQUALS(1U, values.size()); \
ASSERT_EQUALS(B * 2U, values.back().intvalue); ASSERT_EQUALS(B * 2U, values.back().intvalue);\
} while(false)
// enum array // enum array
CHECK("", settings.sizeof_int); CHECK("", settings.sizeof_int);

View File

@ -1090,7 +1090,7 @@ private:
const char wanted[] = "1: class DLLSYM B@1 ;\n" const char wanted[] = "1: class DLLSYM B@1 ;\n"
"2: struct B {\n" "2: struct B {\n"
"3: ~ B ( ) { }\n" "3: ~ B ( ) { }\n"
"4: } ;\n";; "4: } ;\n";
TODO_ASSERT_EQUALS(wanted, expected, tokenize(code, false, "test.cpp")); TODO_ASSERT_EQUALS(wanted, expected, tokenize(code, false, "test.cpp"));
} }

View File

@ -22,6 +22,11 @@ if (BUILD_GUI AND BUILD_TESTS)
${PROJECT_SOURCE_DIR}/gui/codeeditor.cpp) ${PROJECT_SOURCE_DIR}/gui/codeeditor.cpp)
target_include_directories(triage PUBLIC ${PROJECT_SOURCE_DIR}/gui/) target_include_directories(triage PUBLIC ${PROJECT_SOURCE_DIR}/gui/)
target_link_libraries(triage Qt5::Core Qt5::Gui Qt5::Widgets) target_link_libraries(triage Qt5::Core Qt5::Gui Qt5::Widgets)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# TODO: enable this - was added in Clang 8
# Q_UNUSED() in generated code
#target_compile_options(triage PRIVATE -Wno-extra-semi-stmt)
endif()
set(CMAKE_AUTOMOC OFF) set(CMAKE_AUTOMOC OFF)
endif() endif()