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:
parent
c60652630f
commit
1af959af2c
|
@ -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. ")
|
||||
|
|
|
@ -2,11 +2,15 @@ file(GLOB hdrs "*.h")
|
|||
file(GLOB srcs "*.cpp")
|
||||
|
||||
add_library(tinyxml_objs OBJECT ${srcs} ${hdrs})
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
# TODO: needs to be fixed upstream
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
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()
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T>::max();
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ void VarInfo::print()
|
|||
default:
|
||||
status = "?";
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
std::cout << "status=" << status << " "
|
||||
<< "alloctype='" << it->second.type << "' "
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ static bool findPath(const std::string &callId,
|
|||
if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue)
|
||||
break;
|
||||
continue;
|
||||
};
|
||||
}
|
||||
path[index] = functionCall;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2275,7 +2275,7 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok, bool isTemplate
|
|||
case '^':
|
||||
tok->str((v1 ^ v2).str());
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Logical operations
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3010,7 +3010,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
|||
typeCount = 0;
|
||||
singleNameCount = 0;
|
||||
} else if (tok2->str() == "const") {
|
||||
; // just skip "const"
|
||||
// just skip "const"
|
||||
} else if (!hasstruct && variableId.find(tok2->str()) != variableId.end() && tok2->previous()->str() != "::") {
|
||||
++typeCount;
|
||||
tok2 = tok2->next();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -35,7 +35,7 @@ private:
|
|||
settings.addEnabled("style");
|
||||
settings.addEnabled("performance");
|
||||
|
||||
TEST_CASE(BoostForeachContainerModification)
|
||||
TEST_CASE(BoostForeachContainerModification);
|
||||
}
|
||||
|
||||
void check(const char code[]) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<int, string> foo() {}")
|
||||
GET_SYMBOL_DB("std::map<int, string> 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"
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<U, T>{}>::type* = nullptr>\n"
|
||||
"void foo(U x);\n"))
|
||||
"void foo(U x);\n"));
|
||||
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
"template<class t>\n"
|
||||
"T f(const T a, const T b) {\n"
|
||||
" return a < b ? b : a;\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
"template<class T>\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<class T>\n"
|
||||
"struct A {\n"
|
||||
" int x = a < b ? b : a;"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -8097,7 +8097,7 @@ private:
|
|||
" bool h = f::h;\n"
|
||||
"};\n"
|
||||
"template <typename i> using j = typename e<i>::g;\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
"template <typename = void> 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 <bool b> c<b> d;\n"
|
||||
"template <> struct a<int> {\n"
|
||||
"template <typename e> 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 <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
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
"template <int> struct a;\n"
|
||||
"template <class, class b> using c = typename a<int{b::d}>::e;\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
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
|
@ -8151,7 +8151,7 @@ private:
|
|||
"template <class> struct f;\n"
|
||||
"}\n"
|
||||
"template <class c> using g = b::f<e<int, c>>;\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
|
||||
// #9154
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
|
@ -8172,7 +8172,7 @@ private:
|
|||
"template <class, class> struct s;\n"
|
||||
"template <template <class> class t, class... w, template <class> class x,\n"
|
||||
" class... u>\n"
|
||||
"struct s<t<w...>, x<u...>>;\n"))
|
||||
"struct s<t<w...>, x<u...>>;\n"));
|
||||
|
||||
// #9156
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
|
@ -8186,7 +8186,7 @@ private:
|
|||
" template <class... ag> using ah = typename ab<h, ag..., g...>::e;\n"
|
||||
"};\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
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
|
@ -8195,24 +8195,24 @@ private:
|
|||
" using d = a;\n"
|
||||
" d e = {(p1)...};\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
}
|
||||
|
||||
void checkNamespaces() {
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}"))
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}"));
|
||||
}
|
||||
|
||||
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 = 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] {}; }"));
|
||||
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("struct c {\n"
|
||||
" void d() {\n"
|
||||
" int a;\n"
|
||||
" auto b = [this, a] {};\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
|
||||
// #9525
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
|
||||
|
@ -8222,7 +8222,7 @@ private:
|
|||
" return {[] {\n"
|
||||
" if (0) {}\n"
|
||||
" }};\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
|
||||
" template <class b> a(b) {}\n"
|
||||
"};\n"
|
||||
|
@ -8231,7 +8231,7 @@ private:
|
|||
" if (0) {}\n"
|
||||
" return 0;\n"
|
||||
" }};\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
|
||||
" template <class b> a(b) {}\n"
|
||||
"};\n"
|
||||
|
@ -8240,14 +8240,14 @@ private:
|
|||
" if (0) {}\n"
|
||||
" return 0;\n"
|
||||
" }};\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
// #0535
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("template <typename, typename> struct a;\n"
|
||||
"template <typename, typename b> void c() {\n"
|
||||
" ([]() -> decltype(0) {\n"
|
||||
" if (a<b, decltype(0)>::d) {}\n"
|
||||
" });\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
|
||||
// #9563
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("template <typename> struct a;\n"
|
||||
|
@ -8255,7 +8255,7 @@ private:
|
|||
" template <typename d> a(d);\n"
|
||||
"};\n"
|
||||
"void e(\n"
|
||||
" int, a<void()> f = [] {});\n"))
|
||||
" int, a<void()> f = [] {});\n"));
|
||||
|
||||
// #9644
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n"
|
||||
|
@ -8263,14 +8263,14 @@ private:
|
|||
" auto c = [](int d) {\n"
|
||||
" for (char e = 0; d;) {}\n"
|
||||
" };\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
// #9537
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
|
||||
" template <typename b> a(b) {}\n"
|
||||
"};\n"
|
||||
"a c{[] {\n"
|
||||
" if (0) {}\n"
|
||||
"}};\n"))
|
||||
"}};\n"));
|
||||
}
|
||||
void checkIfCppCast() {
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
|
||||
|
@ -8284,7 +8284,7 @@ private:
|
|||
" int f = 0;\n"
|
||||
" if (!const_cast<a *>(&e)->b()) {}\n"
|
||||
" return f;\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
}
|
||||
|
||||
void checkRefQualifiers() {
|
||||
|
@ -8293,56 +8293,56 @@ private:
|
|||
" void b() && {\n"
|
||||
" if (this) {}\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||
" void b() & {\n"
|
||||
" if (this) {}\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||
" auto b() && -> void {\n"
|
||||
" if (this) {}\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||
" auto b() & -> void {\n"
|
||||
" if (this) {}\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||
" auto b(int& x) -> int& {\n"
|
||||
" if (this) {}\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||
" auto b(int& x) -> int&& {\n"
|
||||
" if (this) {}\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||
" auto b(int& x) && -> int& {\n"
|
||||
" if (this) {}\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
// #9524
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int* {\n"
|
||||
" if (0) {}\n"
|
||||
" return 0;\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int** {\n"
|
||||
" if (0) {}\n"
|
||||
" return 0;\n"
|
||||
"};\n"))
|
||||
"};\n"));
|
||||
|
||||
}
|
||||
|
||||
void checkConditionBlock() {
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n"
|
||||
" for (auto b : std::vector<std::vector<int>>{{}, {}}) {}\n"
|
||||
"}\n"))
|
||||
"}\n"));
|
||||
}
|
||||
|
||||
void noCrash1() {
|
||||
|
@ -8350,7 +8350,7 @@ private:
|
|||
"struct A {\n"
|
||||
" A( const std::string &name = "" );\n"
|
||||
"};\n"
|
||||
"A::A( const std::string &name ) { return; }\n"))
|
||||
"A::A( const std::string &name ) { return; }\n"));
|
||||
}
|
||||
|
||||
// #9007
|
||||
|
@ -8367,7 +8367,7 @@ private:
|
|||
"};\n"
|
||||
"template <> d<int>::d(const int &, a::b, double, double);\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[]) {
|
||||
|
|
|
@ -810,12 +810,14 @@ private:
|
|||
ASSERT_EQUALS(1, values.back().intvalue);
|
||||
|
||||
#define CHECK(A, B) \
|
||||
do { \
|
||||
code = "void f() {\n" \
|
||||
" x = sizeof(" A ");\n" \
|
||||
"}"; \
|
||||
values = tokenValues(code,"( " A " )"); \
|
||||
ASSERT_EQUALS(1U, values.size()); \
|
||||
ASSERT_EQUALS(B, values.back().intvalue);
|
||||
ASSERT_EQUALS(B, values.back().intvalue);\
|
||||
} while(false)
|
||||
|
||||
// standard types
|
||||
CHECK("void *", settings.sizeof_pointer);
|
||||
|
@ -849,13 +851,15 @@ private:
|
|||
ASSERT_EQUALS(10, values.back().intvalue);
|
||||
|
||||
#define CHECK(A, B, C, D) \
|
||||
do { \
|
||||
code = "enum " A " E " B " { E0, E1 };\n" \
|
||||
"void f() {\n" \
|
||||
" x = sizeof(" C ");\n" \
|
||||
"}"; \
|
||||
values = tokenValues(code,"( " C " )"); \
|
||||
ASSERT_EQUALS(1U, values.size()); \
|
||||
ASSERT_EQUALS(D, values.back().intvalue);
|
||||
ASSERT_EQUALS(D, values.back().intvalue); \
|
||||
} while(false)
|
||||
|
||||
// enums
|
||||
CHECK("", "", "E", settings.sizeof_int);
|
||||
|
@ -922,6 +926,7 @@ private:
|
|||
#undef CHECK
|
||||
|
||||
#define CHECK(A, B) \
|
||||
do { \
|
||||
code = "enum E " A " { E0, E1 };\n" \
|
||||
"void f() {\n" \
|
||||
" E arrE[] = { E0, E1 };\n" \
|
||||
|
@ -929,7 +934,8 @@ private:
|
|||
"}"; \
|
||||
values = tokenValues(code,"( arrE )"); \
|
||||
ASSERT_EQUALS(1U, values.size()); \
|
||||
ASSERT_EQUALS(B * 2U, values.back().intvalue);
|
||||
ASSERT_EQUALS(B * 2U, values.back().intvalue);\
|
||||
} while(false)
|
||||
|
||||
// enum array
|
||||
CHECK("", settings.sizeof_int);
|
||||
|
@ -955,6 +961,7 @@ private:
|
|||
#undef CHECK
|
||||
|
||||
#define CHECK(A, B) \
|
||||
do { \
|
||||
code = "enum class E " A " { E0, E1 };\n" \
|
||||
"void f() {\n" \
|
||||
" E arrE[] = { E::E0, E::E1 };\n" \
|
||||
|
@ -962,7 +969,8 @@ private:
|
|||
"}"; \
|
||||
values = tokenValues(code,"( arrE )"); \
|
||||
ASSERT_EQUALS(1U, values.size()); \
|
||||
ASSERT_EQUALS(B * 2U, values.back().intvalue);
|
||||
ASSERT_EQUALS(B * 2U, values.back().intvalue);\
|
||||
} while(false)
|
||||
|
||||
// enum array
|
||||
CHECK("", settings.sizeof_int);
|
||||
|
|
|
@ -1090,7 +1090,7 @@ private:
|
|||
const char wanted[] = "1: class DLLSYM B@1 ;\n"
|
||||
"2: struct B {\n"
|
||||
"3: ~ B ( ) { }\n"
|
||||
"4: } ;\n";;
|
||||
"4: } ;\n";
|
||||
TODO_ASSERT_EQUALS(wanted, expected, tokenize(code, false, "test.cpp"));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,11 @@ if (BUILD_GUI AND BUILD_TESTS)
|
|||
${PROJECT_SOURCE_DIR}/gui/codeeditor.cpp)
|
||||
target_include_directories(triage PUBLIC ${PROJECT_SOURCE_DIR}/gui/)
|
||||
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)
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue