From 63e00ea9188d300e5d9a2e0733516e7143e88311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 3 Nov 2023 09:55:44 +0100 Subject: [PATCH] fixed some "Variable can be made constexpr" Rider warnings (#5615) --- cli/cppcheckexecutorsig.cpp | 4 +- cli/stacktrace.cpp | 2 +- gui/mainwindow.cpp | 5 +- gui/projectfiledialog.cpp | 16 +- gui/resultstree.cpp | 34 +-- gui/settingsdialog.h | 2 +- gui/xmlreport.cpp | 4 +- lib/calculate.h | 4 +- lib/checkclass.cpp | 3 +- lib/checkleakautovar.cpp | 8 +- lib/checkother.cpp | 12 +- lib/checkstring.cpp | 2 +- lib/checktype.cpp | 4 +- lib/cppcheck.cpp | 10 +- lib/ctu.cpp | 30 +-- lib/path.cpp | 16 +- lib/summaries.cpp | 2 +- lib/templatesimplifier.cpp | 2 +- lib/tokenlist.cpp | 2 +- lib/valueflow.cpp | 6 +- test/testanalyzerinformation.cpp | 2 +- test/testbufferoverrun.cpp | 116 ++++----- test/testclass.cpp | 10 +- test/testfunctions.cpp | 16 +- test/testimportproject.cpp | 68 +++--- test/testleakautovar.cpp | 84 +++---- test/testlibrary.cpp | 398 +++++++++++++++---------------- test/testmathlib.cpp | 24 +- test/testother.cpp | 30 +-- test/testplatform.cpp | 218 ++++++++--------- test/testprocessexecutor.cpp | 4 +- test/testsingleexecutor.cpp | 4 +- test/testsymboldatabase.cpp | 12 +- test/testthreadexecutor.cpp | 4 +- test/testuninitvar.cpp | 26 +- test/testunusedvar.cpp | 2 +- test/testvalueflow.cpp | 10 +- tools/dmake.cpp | 2 +- tools/triage/mainwindow.cpp | 2 +- 39 files changed, 600 insertions(+), 600 deletions(-) diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp index d1bf58212..0d1156e0a 100644 --- a/cli/cppcheckexecutorsig.cpp +++ b/cli/cppcheckexecutorsig.cpp @@ -51,9 +51,9 @@ // TODO: __USE_DYNAMIC_STACK_SIZE is dependent on the features.h include and not a built-in compiler define, so it might be problematic to depend on it #ifdef __USE_DYNAMIC_STACK_SIZE -static const size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer +static constexpr size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer #else -static const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer +static constexpr size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer #endif static char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler static bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper() diff --git a/cli/stacktrace.cpp b/cli/stacktrace.cpp index bd766c717..1ff4f0389 100644 --- a/cli/stacktrace.cpp +++ b/cli/stacktrace.cpp @@ -35,7 +35,7 @@ void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool lowMem) const int fd = fileno(output); void *callstackArray[32]= {nullptr}; // the less resources the better... const int currentdepth = backtrace(callstackArray, (int)getArrayLength(callstackArray)); - const int offset=2; // some entries on top are within our own exception handling code or libc + constexpr int offset=2; // some entries on top are within our own exception handling code or libc if (maxdepth<0) maxdepth=currentdepth-offset; else diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 842d21b4d..cc812baa4 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -271,13 +271,14 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mUI->mActionEnforceCpp->setActionGroup(mSelectLanguageActions); mUI->mActionAutoDetectLanguage->setActionGroup(mSelectLanguageActions); + // TODO: we no longer default to a Windows platform in CLI - so we should probably also get rid of this in the GUI // For Windows platforms default to Win32 checked platform. // For other platforms default to unspecified/default which means the // platform Cppcheck GUI was compiled on. #if defined(_WIN32) - const Platform::Type defaultPlatform = Platform::Type::Win32W; + constexpr Platform::Type defaultPlatform = Platform::Type::Win32W; #else - const Platform::Type defaultPlatform = Platform::Type::Unspecified; + constexpr Platform::Type defaultPlatform = Platform::Type::Unspecified; #endif PlatformData &platform = mPlatforms.get((Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt()); platform.mActMainWindow->setChecked(true); diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index 5835c4728..89eaf3d1e 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -57,12 +57,12 @@ #include #include -static const char ADDON_MISRA[] = "misra"; -static const char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023"; -static const char CODING_STANDARD_MISRA_CPP_2008[] = "misra-cpp-2008"; -static const char CODING_STANDARD_CERT_C[] = "cert-c-2016"; -static const char CODING_STANDARD_CERT_CPP[] = "cert-cpp-2016"; -static const char CODING_STANDARD_AUTOSAR[] = "autosar"; +static constexpr char ADDON_MISRA[] = "misra"; +static constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023"; +static constexpr char CODING_STANDARD_MISRA_CPP_2008[] = "misra-cpp-2008"; +static constexpr char CODING_STANDARD_CERT_C[] = "cert-c-2016"; +static constexpr char CODING_STANDARD_CERT_CPP[] = "cert-cpp-2016"; +static constexpr char CODING_STANDARD_AUTOSAR[] = "autosar"; /** Return paths from QListWidget */ static QStringList getPaths(const QListWidget *list) @@ -77,7 +77,7 @@ static QStringList getPaths(const QListWidget *list) } /** Platforms shown in the platform combobox */ -static const Platform::Type builtinPlatforms[] = { +static constexpr Platform::Type builtinPlatforms[] = { Platform::Type::Native, Platform::Type::Win32A, Platform::Type::Win32W, @@ -86,7 +86,7 @@ static const Platform::Type builtinPlatforms[] = { Platform::Type::Unix64 }; -static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]); +static constexpr int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]); QStringList ProjectFileDialog::getProjectConfigs(const QString &fileName) { diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 49b5e179f..71494a19d 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -60,25 +60,25 @@ #include #include -static const char COLUMN[] = "column"; -static const char CWE[] = "cwe"; -static const char ERRORID[] = "id"; -static const char FILENAME[] = "file"; -static const char FILE0[] = "file0"; -static const char HASH[] = "hash"; -static const char HIDE[] = "hide"; -static const char INCONCLUSIVE[] = "inconclusive"; -static const char LINE[] = "line"; -static const char MESSAGE[] = "message"; -static const char SEVERITY[] = "severity"; -static const char SINCEDATE[] = "sinceDate"; -static const char SYMBOLNAMES[] = "symbolNames"; -static const char SUMMARY[] = "summary"; -static const char TAGS[] = "tags"; +static constexpr char COLUMN[] = "column"; +static constexpr char CWE[] = "cwe"; +static constexpr char ERRORID[] = "id"; +static constexpr char FILENAME[] = "file"; +static constexpr char FILE0[] = "file0"; +static constexpr char HASH[] = "hash"; +static constexpr char HIDE[] = "hide"; +static constexpr char INCONCLUSIVE[] = "inconclusive"; +static constexpr char LINE[] = "line"; +static constexpr char MESSAGE[] = "message"; +static constexpr char SEVERITY[] = "severity"; +static constexpr char SINCEDATE[] = "sinceDate"; +static constexpr char SYMBOLNAMES[] = "symbolNames"; +static constexpr char SUMMARY[] = "summary"; +static constexpr char TAGS[] = "tags"; // These must match column headers given in ResultsTree::translate() -static const int COLUMN_SINCE_DATE = 6; -static const int COLUMN_TAGS = 7; +static constexpr int COLUMN_SINCE_DATE = 6; +static constexpr int COLUMN_TAGS = 7; ResultsTree::ResultsTree(QWidget * parent) : QTreeView(parent) diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 4c789458f..e04582d80 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -240,7 +240,7 @@ protected: private: void manageStyleControls(); - static const int mLangCodeRole = Qt::UserRole; + static constexpr int mLangCodeRole = Qt::UserRole; bool mPremium; }; diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 0a6234bf1..3e432d623 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -29,8 +29,8 @@ #include #endif -static const char ResultElementName[] = "results"; -static const char VersionAttribute[] = "version"; +static constexpr char ResultElementName[] = "results"; +static constexpr char VersionAttribute[] = "version"; XmlReport::XmlReport(const QString &filename) : Report(filename) diff --git a/lib/calculate.h b/lib/calculate.h index 76117d6e7..b5ed6e3ea 100644 --- a/lib/calculate.h +++ b/lib/calculate.h @@ -52,9 +52,9 @@ R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr) auto wrap = [](T z) { return R{z}; }; - const MathLib::bigint maxBitsShift = sizeof(MathLib::bigint) * 8; + constexpr MathLib::bigint maxBitsShift = sizeof(MathLib::bigint) * 8; // For portability we cannot shift signed integers by 63 bits - const MathLib::bigint maxBitsSignedShift = maxBitsShift - 1; + constexpr MathLib::bigint maxBitsSignedShift = maxBitsShift - 1; switch (MathLib::encodeMultiChar(s)) { case '+': return wrap(x + y); diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 5218a2f3d..b69010bd9 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1117,8 +1117,7 @@ void CheckClass::missingMemberCopyError(const Token *tok, Function::Type functio const std::string message = "$symbol:" + classname + "::" + varname + "\n" + "Member variable '$symbol' is not assigned in the " + ctor + " constructor. Should it be " + action; - const char id[] = "missingMemberCopy"; - reportError(tok, Severity::warning, id, message, CWE398, Certainty::inconclusive); + reportError(tok, Severity::warning, "missingMemberCopy", message, CWE398, Certainty::inconclusive); } void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname, bool inconclusive) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 47cb070b9..0f562d65b 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -54,8 +54,8 @@ static const CWE CWE672(672U); static const CWE CWE415(415U); // Hardcoded allocation types (not from library) -static const int NEW_ARRAY = -2; -static const int NEW = -1; +static constexpr int NEW_ARRAY = -2; +static constexpr int NEW = -1; static const std::array, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}}; static const std::array, 4> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}}; @@ -304,9 +304,9 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken, static const nonneg int recursiveLimit = 300; #elif defined(__MINGW32__) // testrunner crashes with stack overflow in CI - static const nonneg int recursiveLimit = 600; + static constexpr nonneg int recursiveLimit = 600; #else - static const nonneg int recursiveLimit = 1000; + static constexpr nonneg int recursiveLimit = 1000; #endif if (++recursiveCount > recursiveLimit) // maximum number of "else if ()" throw InternalError(startToken, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached.", InternalError::LIMIT); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7679274f4..87867bc77 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3960,9 +3960,9 @@ void CheckOther::checkOverlappingWrite() if (nonOverlappingData->sizeArg <= 0 || nonOverlappingData->sizeArg > args.size()) { if (nonOverlappingData->sizeArg == -1) { ErrorPath errorPath; - const bool macro = true; - const bool pure = true; - const bool follow = true; + constexpr bool macro = true; + constexpr bool pure = true; + constexpr bool follow = true; if (!isSameExpression(mTokenizer->isCPP(), macro, ptr1, ptr2, mSettings->library, pure, follow, &errorPath)) continue; overlappingWriteFunction(tok); @@ -3985,9 +3985,9 @@ void CheckOther::checkOverlappingWrite() continue; ErrorPath errorPath; - const bool macro = true; - const bool pure = true; - const bool follow = true; + constexpr bool macro = true; + constexpr bool pure = true; + constexpr bool follow = true; if (!isSameExpression(mTokenizer->isCPP(), macro, buf1, buf2, mSettings->library, pure, follow, &errorPath)) continue; overlappingWriteFunction(tok); diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index c0647fd21..5dc52d74c 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -140,7 +140,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare() void CheckString::alwaysTrueFalseStringCompareError(const Token *tok, const std::string& str1, const std::string& str2) { - const std::size_t stringLen = 10; + constexpr std::size_t stringLen = 10; const std::string string1 = (str1.size() < stringLen) ? str1 : (str1.substr(0, stringLen-2) + ".."); const std::string string2 = (str2.size() < stringLen) ? str2 : (str2.substr(0, stringLen-2) + ".."); diff --git a/lib/checktype.cpp b/lib/checktype.cpp index f6e029290..b8a3d26d4 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -112,7 +112,7 @@ void CheckType::checkTooBigBitwiseShift() void CheckType::tooBigBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits) { - const char id[] = "shiftTooManyBits"; + constexpr char id[] = "shiftTooManyBits"; if (!tok) { reportError(tok, Severity::error, id, "Shifting 32-bit value by 40 bits is undefined behaviour", CWE758, Certainty::normal); @@ -131,7 +131,7 @@ void CheckType::tooBigBitwiseShiftError(const Token *tok, int lhsbits, const Val void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits) { - const char id[] = "shiftTooManyBitsSigned"; + constexpr char id[] = "shiftTooManyBitsSigned"; const bool cpp14 = mSettings->standards.cpp >= Standards::CPP14; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 2656a6eac..41c4939b1 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -81,10 +81,10 @@ class SymbolDatabase; -static const char Version[] = CPPCHECK_VERSION_STRING; -static const char ExtraVersion[] = ""; +static constexpr char Version[] = CPPCHECK_VERSION_STRING; +static constexpr char ExtraVersion[] = ""; -static const char FILELIST[] = "cppcheck-addon-ctu-file-list"; +static constexpr char FILELIST[] = "cppcheck-addon-ctu-file-list"; static TimerResults s_timerResults; @@ -1636,9 +1636,9 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings) const std::string allDefines = getDefinesFlags(fileSettings.defines); #ifdef _WIN32 - const char exe[] = "clang-tidy.exe"; + constexpr char exe[] = "clang-tidy.exe"; #else - const char exe[] = "clang-tidy"; + constexpr char exe[] = "clang-tidy"; #endif const std::string args = "-quiet -checks=*,-clang-analyzer-*,-llvm* \"" + fileSettings.filename + "\" -- " + allIncludes + allDefines; diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 5105628c7..a67254667 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -39,21 +39,21 @@ #include //--------------------------------------------------------------------------- -static const char ATTR_CALL_ID[] = "call-id"; -static const char ATTR_CALL_FUNCNAME[] = "call-funcname"; -static const char ATTR_CALL_ARGNR[] = "call-argnr"; -static const char ATTR_CALL_ARGEXPR[] = "call-argexpr"; -static const char ATTR_CALL_ARGVALUETYPE[] = "call-argvaluetype"; -static const char ATTR_CALL_ARGVALUE[] = "call-argvalue"; -static const char ATTR_WARNING[] = "warning"; -static const char ATTR_LOC_FILENAME[] = "file"; -static const char ATTR_LOC_LINENR[] = "line"; -static const char ATTR_LOC_COLUMN[] = "col"; -static const char ATTR_INFO[] = "info"; -static const char ATTR_MY_ID[] = "my-id"; -static const char ATTR_MY_ARGNR[] = "my-argnr"; -static const char ATTR_MY_ARGNAME[] = "my-argname"; -static const char ATTR_VALUE[] = "value"; +static constexpr char ATTR_CALL_ID[] = "call-id"; +static constexpr char ATTR_CALL_FUNCNAME[] = "call-funcname"; +static constexpr char ATTR_CALL_ARGNR[] = "call-argnr"; +static constexpr char ATTR_CALL_ARGEXPR[] = "call-argexpr"; +static constexpr char ATTR_CALL_ARGVALUETYPE[] = "call-argvaluetype"; +static constexpr char ATTR_CALL_ARGVALUE[] = "call-argvalue"; +static constexpr char ATTR_WARNING[] = "warning"; +static constexpr char ATTR_LOC_FILENAME[] = "file"; +static constexpr char ATTR_LOC_LINENR[] = "line"; +static constexpr char ATTR_LOC_COLUMN[] = "col"; +static constexpr char ATTR_INFO[] = "info"; +static constexpr char ATTR_MY_ID[] = "my-id"; +static constexpr char ATTR_MY_ARGNR[] = "my-argnr"; +static constexpr char ATTR_MY_ARGNAME[] = "my-argname"; +static constexpr char ATTR_VALUE[] = "value"; int CTU::maxCtuDepth = 2; diff --git a/lib/path.cpp b/lib/path.cpp index 1c1c724d3..013044fd0 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -60,11 +60,11 @@ static constexpr bool caseInsensitiveFilesystem() std::string Path::toNativeSeparators(std::string path) { #if defined(_WIN32) - const char separ = '/'; - const char native = '\\'; + constexpr char separ = '/'; + constexpr char native = '\\'; #else - const char separ = '\\'; - const char native = '/'; + constexpr char separ = '\\'; + constexpr char native = '/'; #endif std::replace(path.begin(), path.end(), separ, native); return path; @@ -72,8 +72,8 @@ std::string Path::toNativeSeparators(std::string path) std::string Path::fromNativeSeparators(std::string path) { - const char nonnative = '\\'; - const char newsepar = '/'; + constexpr char nonnative = '\\'; + constexpr char newsepar = '/'; std::replace(path.begin(), path.end(), nonnative, newsepar); return path; } @@ -250,9 +250,9 @@ std::string Path::getAbsoluteFilePath(const std::string& filePath) std::string Path::stripDirectoryPart(const std::string &file) { #if defined(_WIN32) && !defined(__MINGW32__) - const char native = '\\'; + constexpr char native = '\\'; #else - const char native = '/'; + constexpr char native = '/'; #endif const std::string::size_type p = file.rfind(native); diff --git a/lib/summaries.cpp b/lib/summaries.cpp index 7ad8a0b1b..21892500c 100644 --- a/lib/summaries.cpp +++ b/lib/summaries.cpp @@ -171,7 +171,7 @@ void Summaries::loadReturn(const std::string &buildDir, std::set &s std::string line; while (std::getline(fin, line)) { // Get function name - const std::string::size_type pos1 = 0; + constexpr std::string::size_type pos1 = 0; const std::string::size_type pos2 = line.find(' ', pos1); const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); std::vector call = getSummaryData(line, "call"); diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 9a07623f5..fa7c02c01 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -3763,7 +3763,7 @@ void TemplateSimplifier::simplifyTemplates(const std::time_t maxtime) mTokenizer.calculateScopes(); unsigned int passCount = 0; - const unsigned int passCountMax = 10; + constexpr unsigned int passCountMax = 10; for (; passCount < passCountMax; ++passCount) { if (passCount) { // it may take more than one pass to simplify type aliases diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 1e90b9406..c1f4802e5 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -43,7 +43,7 @@ // How many compileExpression recursions are allowed? // For practical code this could be endless. But in some special torture test // there needs to be a limit. -static const int AST_MAX_DEPTH = 150; +static constexpr int AST_MAX_DEPTH = 150; TokenList::TokenList(const Settings* settings) : diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 473f8c000..6f5922938 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -407,7 +407,7 @@ static ValueFlow::Value castValue(ValueFlow::Value value, const ValueType::Sign } } if (bit < MathLib::bigint_bits) { - const MathLib::biguint one = 1; + constexpr MathLib::biguint one = 1; value.intvalue &= (one << bit) - 1; if (sign == ValueType::Sign::SIGNED && value.intvalue & (one << (bit - 1))) { value.intvalue |= ~((one << bit) - 1ULL); @@ -3158,7 +3158,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer { } void setupExprVarIds(const Token* start, int depth = 0) { - const int maxDepth = 4; + constexpr int maxDepth = 4; if (depth > maxDepth) return; visitAstNodes(start, [&](const Token* tok) { @@ -8459,7 +8459,7 @@ struct IteratorConditionHandler : SimpleConditionHandler { if (!tok->astOperand1() || !tok->astOperand2()) return {}; - const ValueFlow::Value::ValueKind kind = ValueFlow::Value::ValueKind::Known; + constexpr ValueFlow::Value::ValueKind kind = ValueFlow::Value::ValueKind::Known; std::list values = getIteratorValues(tok->astOperand1()->values(), &kind); if (!values.empty()) { cond.vartok = tok->astOperand2(); diff --git a/test/testanalyzerinformation.cpp b/test/testanalyzerinformation.cpp index 0c0c0bde7..6727efb1f 100644 --- a/test/testanalyzerinformation.cpp +++ b/test/testanalyzerinformation.cpp @@ -33,7 +33,7 @@ private: } void getAnalyzerInfoFile() const { - const char filesTxt[] = "file1.a4::file1.c\n"; + constexpr char filesTxt[] = "file1.a4::file1.c\n"; std::istringstream f1(filesTxt); ASSERT_EQUALS("file1.a4", getAnalyzerInfoFileFromFilesTxt(f1, "file1.c", "")); std::istringstream f2(filesTxt); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index dd21618fb..63491d85f 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3597,17 +3597,17 @@ private: } void buffer_overrun_readSizeFromCfg() { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " false\n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " false\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); // Attempt to get size from Cfg files, no false positives if size is not specified @@ -4149,17 +4149,17 @@ private: // extracttests.disable void minsize_argvalue() { - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).severity(Severity::warning).build(); settings.platform.sizeof_wchar_t = 4; @@ -4286,18 +4286,18 @@ private: } void minsize_sizeof() { - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void f() {\n" @@ -4346,19 +4346,19 @@ private: } void minsize_strlen() { - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); // formatstr.. @@ -4459,17 +4459,17 @@ private: } void minsize_mul() { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void f() {\n" diff --git a/test/testclass.cpp b/test/testclass.cpp index e8ca03ddf..9006fd101 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3444,11 +3444,11 @@ private: } void memsetOnStdPodType() { // Ticket #5901 - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + ""; const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); checkNoMemset("class A {\n" diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 8eacf8b1c..e223e74b0 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1296,14 +1296,14 @@ private: } void checkIgnoredReturnValue() { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata, sizeof(xmldata)).build(); check("void foo() {\n" diff --git a/test/testimportproject.cpp b/test/testimportproject.cpp index bdddb128e..fb6a66707 100644 --- a/test/testimportproject.cpp +++ b/test/testimportproject.cpp @@ -112,11 +112,11 @@ private: } void importCompileCommands1() const { - const char json[] = R"([{ + constexpr char json[] = R"([{ "directory": "/tmp", "command": "gcc -DTEST1 -DTEST2=2 -o /tmp/src.o -c /tmp/src.c", "file": "/tmp/src.c" - }])"; + }])"; std::istringstream istr(json); TestImporter importer; ASSERT_EQUALS(true, importer.importCompileCommands(istr)); @@ -138,11 +138,11 @@ private: ASSERT_EQUALS(1, importer.fileSettings.size()); ASSERT_EQUALS("C:/bar.c", importer.fileSettings.cbegin()->filename); #else - const char json[] = R"([{ + constexpr char json[] = R"([{ "directory": "/foo", "command": "gcc -c bar.c", "file": "/bar.c" - }])"; + }])"; std::istringstream istr(json); TestImporter importer; ASSERT_EQUALS(true, importer.importCompileCommands(istr)); @@ -165,11 +165,11 @@ private: } void importCompileCommands4() const { - const char json[] = R"([{ + constexpr char json[] = R"([{ "directory": "/tmp/", "command": "gcc -c src.mm", "file": "src.mm" - }])"; + }])"; std::istringstream istr(json); TestImporter importer; ASSERT_EQUALS(true, importer.importCompileCommands(istr)); @@ -177,7 +177,7 @@ private: } void importCompileCommands5() const { - const char json[] = + constexpr char json[] = R"([{ "directory": "C:/Users/dan/git/build-test-cppcheck-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug", "command": "C:\\PROGRA~2\\MICROS~1\\2019\\COMMUN~1\\VC\\Tools\\MSVC\\1427~1.291\\bin\\HostX64\\x64\\cl.exe /nologo /TP -IC:\\Users\\dan\\git\\test-cppcheck\\mylib\\src /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++17 /Fomylib\\CMakeFiles\\mylib.dir\\src\\foobar\\mylib.cpp.obj /FdTARGET_COMPILE_PDB /FS -c C:\\Users\\dan\\git\\test-cppcheck\\mylib\\src\\foobar\\mylib.cpp", @@ -196,7 +196,7 @@ private: } void importCompileCommands6() const { - const char json[] = + constexpr char json[] = R"([{ "directory": "C:/Users/dan/git/build-test-cppcheck-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug", "command": "C:\\PROGRA~2\\MICROS~1\\2019\\COMMUN~1\\VC\\Tools\\MSVC\\1427~1.291\\bin\\HostX64\\x64\\cl.exe /nologo /TP -IC:\\Users\\dan\\git\\test-cppcheck\\mylib\\src -I\"C:\\Users\\dan\\git\\test-cppcheck\\mylib\\second src\" /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++17 /Fomylib\\CMakeFiles\\mylib.dir\\src\\foobar\\mylib.cpp.obj /FdTARGET_COMPILE_PDB /FS -c C:\\Users\\dan\\git\\test-cppcheck\\mylib\\src\\foobar\\mylib.cpp", @@ -218,7 +218,7 @@ private: void importCompileCommands7() const { // cmake -DFILESDIR="/some/path" .. - const char json[] = + constexpr char json[] = R"([{ "directory": "/home/danielm/cppcheck 2/b/lib", "command": "/usr/bin/c++ -DFILESDIR=\\\"/some/path\\\" -I\"/home/danielm/cppcheck 2/b/lib\" -isystem \"/home/danielm/cppcheck 2/externals\" \"/home/danielm/cppcheck 2/lib/astutils.cpp\"", @@ -238,7 +238,7 @@ private: void importCompileCommands8() const { // cmake -DFILESDIR="C:\Program Files\Cppcheck" -G"NMake Makefiles" .. - const char json[] = + constexpr char json[] = R"([{ "directory": "C:/Users/danielm/cppcheck/build/lib", "command": "C:\\PROGRA~2\\MICROS~2\\2017\\COMMUN~1\\VC\\Tools\\MSVC\\1412~1.258\\bin\\Hostx64\\x64\\cl.exe /nologo /TP -DFILESDIR=\"\\\"C:\\Program Files\\Cppcheck\\\"\" -IC:\\Users\\danielm\\cppcheck\\build\\lib -IC:\\Users\\danielm\\cppcheck\\lib -c C:\\Users\\danielm\\cppcheck\\lib\\astutils.cpp", @@ -251,7 +251,7 @@ private: void importCompileCommands9() const { // IAR output (https://sourceforge.net/p/cppcheck/discussion/general/thread/608af51e0a/) - const char json[] = + constexpr char json[] = R"([{ "arguments" : [ "powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File d:\\Projekte\\xyz\\firmware\\app\\xyz-lib\\build.ps1 -IAR -COMPILER_PATH \"c:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 9.0\" -CONTROLLER CC1310F128 -LIB LIB_PERMANENT -COMPILER_DEFINES \"CC1310_HFXO_FREQ=24000000 DEBUG\"" @@ -266,7 +266,7 @@ private: } void importCompileCommands10() const { // #10887 - const char json[] = + constexpr char json[] = R"([{ "file": "/home/danielm/cppcheck/1/test folder/1.c" , "directory": "", @@ -285,7 +285,7 @@ private: } void importCompileCommands11() const { // include path order - const char json[] = + constexpr char json[] = R"([{ "file": "1.c" , "directory": "/x", @@ -307,9 +307,9 @@ private: } void importCompileCommandsArgumentsSection() const { - const char json[] = "[ { \"directory\": \"/tmp/\"," - "\"arguments\": [\"gcc\", \"-c\", \"src.c\"]," - "\"file\": \"src.c\" } ]"; + constexpr char json[] = "[ { \"directory\": \"/tmp/\"," + "\"arguments\": [\"gcc\", \"-c\", \"src.c\"]," + "\"file\": \"src.c\" } ]"; std::istringstream istr(json); TestImporter importer; ASSERT_EQUALS(true, importer.importCompileCommands(istr)); @@ -318,8 +318,8 @@ private: } void importCompileCommandsNoCommandSection() const { - const char json[] = "[ { \"directory\": \"/tmp/\"," - "\"file\": \"src.mm\" } ]"; + constexpr char json[] = "[ { \"directory\": \"/tmp/\"," + "\"file\": \"src.mm\" } ]"; std::istringstream istr(json); TestImporter importer; ASSERT_EQUALS(false, importer.importCompileCommands(istr)); @@ -327,22 +327,22 @@ private: } void importCppcheckGuiProject() const { - const char xml[] = "\n" - "\n" - " \n" - " out1\n" - " true\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " test test\n" - "\n"; + constexpr char xml[] = "\n" + "\n" + " \n" + " out1\n" + " true\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " test test\n" + "\n"; std::istringstream istr(xml); Settings s; TestImporter project; diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 4e1461220..a08bc2d64 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -39,28 +39,28 @@ private: Settings settings; void run() override { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " malloc\n" - " realloc\n" - " free\n" - " \n" - " \n" - " socket\n" - " close\n" - " \n" - " \n" - " fopen\n" - " freopen\n" - " fclose\n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " malloc\n" + " realloc\n" + " free\n" + " \n" + " \n" + " socket\n" + " close\n" + " \n" + " \n" + " fopen\n" + " freopen\n" + " fclose\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; settings = settingsBuilder(settings).libraryxml(xmldata, sizeof(xmldata)).build(); // Assign @@ -2777,18 +2777,18 @@ private: } void functionCallCastConfig() { // #9652 - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings settingsFunctionCall = settingsBuilder(settings).libraryxml(xmldata, sizeof(xmldata)).build(); check("void test_func()\n" @@ -2814,14 +2814,14 @@ private: } void functionCallLeakIgnoreConfig() { // #7923 - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " false\n" - " \n" - " \n" - "\n"; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " false\n" + " \n" + " \n" + "\n"; const Settings settingsLeakIgnore = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void f() {\n" " double* a = new double[1024];\n" diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 430ac100f..7fa157ad0 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -102,19 +102,19 @@ private: void empty() const { // Reading an empty library file is considered to be OK - const char xmldata[] = "\n"; + constexpr char xmldata[] = "\n"; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.functions.empty()); } void function() const { - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + ""; TokenList tokenList(nullptr); std::istringstream istr("foo();"); @@ -129,12 +129,12 @@ private: } void function_match_scope() const { - const char xmldata[] = "\n" - "\n" - " \n" - " " - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " " + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -155,12 +155,12 @@ private: } void function_match_args() const { - const char xmldata[] = "\n" - "\n" - " \n" - " " - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " " + " \n" + ""; TokenList tokenList(nullptr); std::istringstream istr("foo();"); // <- too few arguments, not library function @@ -174,13 +174,13 @@ private: } void function_match_args_default() const { - const char xmldata[] = "\n" - "\n" - " \n" - " " - " " - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " " + " " + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -224,12 +224,12 @@ private: } void function_match_var() const { - const char xmldata[] = "\n" - "\n" - " \n" - " " - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " " + " \n" + ""; TokenList tokenList(nullptr); std::istringstream istr("Fred foo(123);"); // <- Variable declaration, not library function @@ -243,16 +243,16 @@ private: } void function_arg() const { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -266,12 +266,12 @@ private: } void function_arg_any() const { - const char xmldata[] = "\n" - "\n" - "\n" - " \n" - "\n" - ""; + constexpr char xmldata[] = "\n" + "\n" + "\n" + " \n" + "\n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -279,13 +279,13 @@ private: } void function_arg_variadic() const { - const char xmldata[] = "\n" - "\n" - "\n" - " \n" - " \n" - "\n" - ""; + constexpr char xmldata[] = "\n" + "\n" + "\n" + " \n" + " \n" + "\n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -303,15 +303,15 @@ private: } void function_arg_direction() const { - const char xmldata[] = "\n" - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - "\n" - ""; + constexpr char xmldata[] = "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + "\n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -328,22 +328,22 @@ private: } void function_arg_valid() const { - const char xmldata[] = "\n" - "\n" - " \n" - " 1:\n" - " -7:0\n" - " 1:5,8\n" - " -1,5\n" - " :1,5\n" - " 1.5:\n" - " -6.7:-5.5,-3.3:-2.7\n" - " 0.0:\n" - " :2.0\n" - " 0.0\n" - " !0.0\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " 1:\n" + " -7:0\n" + " 1:5,8\n" + " -1,5\n" + " :1,5\n" + " 1.5:\n" + " -6.7:-5.5,-3.3:-2.7\n" + " 0.0:\n" + " :2.0\n" + " 0.0\n" + " !0.0\n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -476,16 +476,16 @@ private: } void function_arg_minsize() const { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -539,12 +539,12 @@ private: } void function_namespace() const { - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -568,12 +568,12 @@ private: } void function_method() const { - const char xmldata[] = "\n" - "\n" - " \n" - " false\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " false\n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -595,12 +595,12 @@ private: } void function_baseClassMethod() const { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -621,15 +621,15 @@ private: } void function_warn() const { - const char xmldata[] = "\n" - "\n" - " \n" - " Message\n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " Message\n" + " \n" + " \n" + " \n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -657,13 +657,13 @@ private: } void memory() const { - const char xmldata[] = "\n" - "\n" - " \n" - " CreateX\n" - " DeleteX\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " CreateX\n" + " DeleteX\n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -677,20 +677,20 @@ private: ASSERT(df && df->arg == 1); } void memory2() const { - const char xmldata1[] = "\n" - "\n" - " \n" - " malloc\n" - " free\n" - " \n" - ""; - const char xmldata2[] = "\n" - "\n" - " \n" - " foo\n" - " free\n" - " \n" - ""; + constexpr char xmldata1[] = "\n" + "\n" + " \n" + " malloc\n" + " free\n" + " \n" + ""; + constexpr char xmldata2[] = "\n" + "\n" + " \n" + " foo\n" + " free\n" + " \n" + ""; Library library; ASSERT_EQUALS(true, loadxmldata(library, xmldata1, sizeof(xmldata1))); @@ -700,13 +700,13 @@ private: ASSERT_EQUALS(library.deallocId("free"), library.allocId("foo")); } void memory3() const { - const char xmldata[] = "\n" - "\n" - " \n" - " CreateX\n" - " DeleteX\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " CreateX\n" + " DeleteX\n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -719,13 +719,13 @@ private: } void resource() const { - const char xmldata[] = "\n" - "\n" - " \n" - " CreateX\n" - " DeleteX\n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " CreateX\n" + " DeleteX\n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -737,13 +737,13 @@ private: void podtype() const { { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); // s8 @@ -791,37 +791,37 @@ private: } void container() const { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" // Inherits all but templateParameter - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" // Inherits all but templateParameter + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); @@ -936,23 +936,23 @@ private: void version() const { { - const char xmldata[] = "\n" - "\n" - ""; + constexpr char xmldata[] = "\n" + "\n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); } { - const char xmldata[] = "\n" - "\n" - ""; + constexpr char xmldata[] = "\n" + "\n" + ""; Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); } { - const char xmldata[] = "\n" - "\n" - ""; + constexpr char xmldata[] = "\n" + "\n" + ""; Library library; const Library::Error err = readLibrary(library, xmldata); ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::UNSUPPORTED_FORMAT); diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 71ca37379..1af3f7bd9 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -355,12 +355,12 @@ private: // min/max and out-of-bounds - hex { - const MathLib::bigint i = 0xFFFFFFFFFFFFFFFF; + constexpr MathLib::bigint i = 0xFFFFFFFFFFFFFFFF; ASSERT_EQUALS(i, MathLib::toBigNumber(std::to_string(i))); ASSERT_EQUALS(i, MathLib::toBigNumber("0xFFFFFFFFFFFFFFFF")); } { - const MathLib::bigint i = -0xFFFFFFFFFFFFFFFF; + constexpr MathLib::bigint i = -0xFFFFFFFFFFFFFFFF; ASSERT_EQUALS(i, MathLib::toBigNumber(std::to_string(i))); ASSERT_EQUALS(i, MathLib::toBigNumber("-0xFFFFFFFFFFFFFFFF")); } @@ -370,12 +370,12 @@ private: // min/max and out-of-bounds - octal { - const MathLib::bigint i = 01777777777777777777777; + constexpr MathLib::bigint i = 01777777777777777777777; ASSERT_EQUALS(i, MathLib::toBigNumber(std::to_string(i))); ASSERT_EQUALS(i, MathLib::toBigNumber("01777777777777777777777")); } { - const MathLib::bigint i = -01777777777777777777777; + constexpr MathLib::bigint i = -01777777777777777777777; ASSERT_EQUALS(i, MathLib::toBigNumber(std::to_string(i))); ASSERT_EQUALS(i, MathLib::toBigNumber("-01777777777777777777777")); } @@ -387,12 +387,12 @@ private: SUPPRESS_WARNING_CLANG_PUSH("-Wimplicitly-unsigned-literal") SUPPRESS_WARNING_GCC_PUSH("-Woverflow") { - const MathLib::bigint i = 18446744073709551615; + constexpr MathLib::bigint i = 18446744073709551615; ASSERT_EQUALS(i, MathLib::toBigNumber(std::to_string(i))); ASSERT_EQUALS(i, MathLib::toBigNumber("18446744073709551615")); } { - const MathLib::bigint i = -18446744073709551615; + constexpr MathLib::bigint i = -18446744073709551615; ASSERT_EQUALS(i, MathLib::toBigNumber(std::to_string(i))); ASSERT_EQUALS(i, MathLib::toBigNumber("-18446744073709551615")); } @@ -520,12 +520,12 @@ private: // min/max and out-of-bounds - hex { - const MathLib::biguint u = 0xFFFFFFFFFFFFFFFF; + constexpr MathLib::biguint u = 0xFFFFFFFFFFFFFFFF; ASSERT_EQUALS(u, MathLib::toBigUNumber(std::to_string(u))); ASSERT_EQUALS(u, MathLib::toBigUNumber("0xFFFFFFFFFFFFFFFF")); } { - const MathLib::biguint u = -0xFFFFFFFFFFFFFFFF; + constexpr MathLib::biguint u = -0xFFFFFFFFFFFFFFFF; ASSERT_EQUALS(u, MathLib::toBigUNumber(std::to_string(u))); ASSERT_EQUALS(u, MathLib::toBigUNumber("-0xFFFFFFFFFFFFFFFF")); } @@ -535,12 +535,12 @@ private: // min/max and out-of-bounds - octal { - const MathLib::biguint u = 01777777777777777777777; + constexpr MathLib::biguint u = 01777777777777777777777; ASSERT_EQUALS(u, MathLib::toBigUNumber(std::to_string(u))); ASSERT_EQUALS(u, MathLib::toBigUNumber("01777777777777777777777")); } { - const MathLib::biguint u = -01777777777777777777777; + constexpr MathLib::biguint u = -01777777777777777777777; ASSERT_EQUALS(u, MathLib::toBigUNumber(std::to_string(u))); ASSERT_EQUALS(u, MathLib::toBigUNumber("-01777777777777777777777")); } @@ -552,12 +552,12 @@ private: SUPPRESS_WARNING_CLANG_PUSH("-Wimplicitly-unsigned-literal") SUPPRESS_WARNING_GCC_PUSH("-Woverflow") { - const MathLib::biguint u = 18446744073709551615; + constexpr MathLib::biguint u = 18446744073709551615; ASSERT_EQUALS(u, MathLib::toBigUNumber(std::to_string(u))); ASSERT_EQUALS(u, MathLib::toBigUNumber("18446744073709551615")); } { - const MathLib::biguint u = -18446744073709551615; + constexpr MathLib::biguint u = -18446744073709551615; ASSERT_EQUALS(u, MathLib::toBigUNumber(std::to_string(u))); ASSERT_EQUALS(u, MathLib::toBigUNumber("-18446744073709551615")); } diff --git a/test/testother.cpp b/test/testother.cpp index 62173127c..0f20e0304 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4702,13 +4702,13 @@ private: "}", nullptr, false, false); ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); - const char xmldata[] = "\n" - "\n" - " \n" - " true\n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " true\n" + " \n" + " \n" + ""; Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void foo() {\n" @@ -6391,14 +6391,14 @@ private: } void duplicateExpression3() { - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void foo() {\n" diff --git a/test/testplatform.cpp b/test/testplatform.cpp index dd7c8b216..0b680be23 100644 --- a/test/testplatform.cpp +++ b/test/testplatform.cpp @@ -55,7 +55,7 @@ private: void empty() const { // An empty platform file does not change values, only the type. - const char xmldata[] = "\n"; + constexpr char xmldata[] = "\n"; Platform platform; // TODO: this should fail - platform files need to be complete TODO_ASSERT(!readPlatform(platform, xmldata)); @@ -189,24 +189,24 @@ private: void valid_config_file_1() const { // Valid platform configuration with all possible values specified. // Similar to the avr8 platform file. - const char xmldata[] = "\n" - "\n" - " 8\n" - " unsigned\n" - " \n" - " 1\n" - " 2\n" - " 2\n" - " 4\n" - " 8\n" - " 4\n" - " 4\n" - " 4\n" - " 2\n" - " 2\n" - " 2\n" - " \n" - " "; + constexpr char xmldata[] = "\n" + "\n" + " 8\n" + " unsigned\n" + " \n" + " 1\n" + " 2\n" + " 2\n" + " 4\n" + " 8\n" + " 4\n" + " 4\n" + " 4\n" + " 2\n" + " 2\n" + " 2\n" + " \n" + " "; Platform platform; ASSERT(readPlatform(platform, xmldata)); ASSERT_EQUALS(Platform::Type::File, platform.type); @@ -233,24 +233,24 @@ private: void valid_config_file_2() const { // Valid platform configuration with all possible values specified and // char_bit > 8. - const char xmldata[] = "\n" - "\n" - " 20\n" - " signed\n" - " \n" - " 1\n" - " 2\n" - " 3\n" - " 4\n" - " 5\n" - " 6\n" - " 7\n" - " 8\n" - " 9\n" - " 10\n" - " 11\n" - " \n" - " "; + constexpr char xmldata[] = "\n" + "\n" + " 20\n" + " signed\n" + " \n" + " 1\n" + " 2\n" + " 3\n" + " 4\n" + " 5\n" + " 6\n" + " 7\n" + " 8\n" + " 9\n" + " 10\n" + " 11\n" + " \n" + " "; Platform platform; ASSERT(readPlatform(platform, xmldata)); ASSERT_EQUALS(Platform::Type::File, platform.type); @@ -277,24 +277,24 @@ private: void valid_config_file_3() const { // Valid platform configuration without any usable information. // Similar like an empty file. - const char xmldata[] = "\n" - "\n" - " 8\n" - " unsigned\n" - " \n" - " 1\n" - " 2\n" - " 3\n" - " 4\n" - " 5\n" - " 6\n" - " 7\n" - " 8\n" - " 9\n" - " 10\n" - " 11\n" - " \n" - " "; + constexpr char xmldata[] = "\n" + "\n" + " 8\n" + " unsigned\n" + " \n" + " 1\n" + " 2\n" + " 3\n" + " 4\n" + " 5\n" + " 6\n" + " 7\n" + " 8\n" + " 9\n" + " 10\n" + " 11\n" + " \n" + " "; Platform platform; // TODO: needs to fail - files need to be complete TODO_ASSERT(!readPlatform(platform, xmldata)); @@ -303,24 +303,24 @@ private: void valid_config_file_4() const { // Valid platform configuration with all possible values specified and // set to 0. - const char xmldata[] = "\n" - "\n" - " 0\n" - " z\n" - " \n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " 0\n" - " \n" - " "; + constexpr char xmldata[] = "\n" + "\n" + " 0\n" + " z\n" + " \n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " 0\n" + " \n" + " "; Platform platform; ASSERT(readPlatform(platform, xmldata)); ASSERT_EQUALS(Platform::Type::File, platform.type); @@ -346,24 +346,24 @@ private: void invalid_config_file_1() const { // Invalid XML file: mismatching elements "boolt" vs "bool". - const char xmldata[] = "\n" - "\n" - " 8\n" - " unsigned\n" - " \n" - " 1\n" - " 2\n" - " 2\n" - " 4\n" - " 8\n" - " 4\n" - " 4\n" - " 4\n" - " 2\n" - " 2\n" - " 2\n" - " \n" - " "; + constexpr char xmldata[] = "\n" + "\n" + " 8\n" + " unsigned\n" + " \n" + " 1\n" + " 2\n" + " 2\n" + " 4\n" + " 8\n" + " 4\n" + " 4\n" + " 4\n" + " 2\n" + " 2\n" + " 2\n" + " \n" + " "; Platform platform; ASSERT(!readPlatform(platform, xmldata)); } @@ -371,24 +371,24 @@ private: void empty_elements() const { // Valid platform configuration without any usable information. // Similar like an empty file. - const char xmldata[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " "; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " "; Platform platform; ASSERT(!readPlatform(platform, xmldata)); } diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index 816ee9479..793cbc8cf 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -289,9 +289,9 @@ private: return; #ifdef _WIN32 - const char exe[] = "clang-tidy.exe"; + constexpr char exe[] = "clang-tidy.exe"; #else - const char exe[] = "clang-tidy"; + constexpr char exe[] = "clang-tidy"; #endif (void)exe; diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 41582b643..cbb635725 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -276,9 +276,9 @@ private: return; #ifdef _WIN32 - const char exe[] = "clang-tidy.exe"; + constexpr char exe[] = "clang-tidy.exe"; #else - const char exe[] = "clang-tidy"; + constexpr char exe[] = "clang-tidy"; #endif const std::string file = fprefix() + "_001.cpp"; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index fa7fba6ab..06d4d1915 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6167,7 +6167,7 @@ private: ASSERT(db); const Scope * bar = db->findScopeByName("bar"); ASSERT(bar != nullptr); - const unsigned int linenrs[2] = { 2, 1 }; + constexpr unsigned int linenrs[2] = { 2, 1 }; unsigned int index = 0; for (const Token * tok = bar->bodyStart->next(); tok != bar->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%name% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) { @@ -8520,9 +8520,9 @@ private: { // Char types Settings settings; - const Library::PodType char8 = { 1, 'u' }; - const Library::PodType char16 = { 2, 'u' }; - const Library::PodType char32 = { 4, 'u' }; + constexpr Library::PodType char8 = { 1, 'u' }; + constexpr Library::PodType char16 = { 2, 'u' }; + constexpr Library::PodType char32 = { 4, 'u' }; settings.library.mPodTypes["char8_t"] = char8; settings.library.mPodTypes["char16_t"] = char16; settings.library.mPodTypes["char32_t"] = char32; @@ -8539,8 +8539,8 @@ private: { // PodType Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).build(); - const Library::PodType u32 = { 4, 'u' }; - const Library::PodType podtype2 = { 0, 'u', Library::PodType::Type::INT }; + constexpr Library::PodType u32 = { 4, 'u' }; + constexpr Library::PodType podtype2 = { 0, 'u', Library::PodType::Type::INT }; settingsWin64.library.mPodTypes["u32"] = u32; settingsWin64.library.mPodTypes["xyz::x"] = u32; settingsWin64.library.mPodTypes["podtype2"] = podtype2; diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 1f291469a..a145cc328 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -288,9 +288,9 @@ private: return; #ifdef _WIN32 - const char exe[] = "clang-tidy.exe"; + constexpr char exe[] = "clang-tidy.exe"; #else - const char exe[] = "clang-tidy"; + constexpr char exe[] = "clang-tidy"; #endif const std::string file = fprefix() + "_1.cpp"; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 74ca1a898..645caf390 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -833,10 +833,10 @@ private: { // Ticket #6701 - Variable name is a POD type according to cfg - const char xmldata[] = "\n" - "" - " " - ""; + constexpr char xmldata[] = "\n" + "" + " " + ""; const Settings s = settingsBuilder(settings).libraryxml(xmldata, sizeof(xmldata)).build(); checkUninitVar("void f() {\n" " Fred _tm;\n" @@ -4470,15 +4470,15 @@ private: ASSERT_EQUALS("", errout.str()); { - const char argDirectionsTestXmlData[] = "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - ""; + constexpr char argDirectionsTestXmlData[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; const Settings s = settingsBuilder(settings).libraryxml(argDirectionsTestXmlData, sizeof(argDirectionsTestXmlData)).build(); checkUninitVar("struct AB { int a; };\n" diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 28a98c3e9..8f6833625 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -5354,7 +5354,7 @@ private: } void localvarOp() { - const char op[] = "+-*/%&|^"; + constexpr char op[] = "+-*/%&|^"; for (const char *p = op; *p; ++p) { std::string code("int main()\n" "{\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 02231bc64..13d3b5bdd 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -46,11 +46,11 @@ private: void run() override { // strcpy, abort cfg - const char cfg[] = "\n" - "\n" - " \n" - " true \n" // abort is a noreturn function - ""; + constexpr char cfg[] = "\n" + "\n" + " \n" + " true \n" // abort is a noreturn function + ""; settings = settingsBuilder(settings).libraryxml(cfg, sizeof(cfg)).build(); TEST_CASE(valueFlowNumber); diff --git a/tools/dmake.cpp b/tools/dmake.cpp index c9825fc64..886738d58 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -431,7 +431,7 @@ int main(int argc, char **argv) } } - static const char makefile[] = "Makefile"; + static constexpr char makefile[] = "Makefile"; std::ofstream fout(makefile, std::ios_base::trunc); if (!fout.is_open()) { std::cerr << "An error occurred while trying to open " diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index d816bc005..2eac338d2 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -64,7 +64,7 @@ class QWidget; const QString WORK_FOLDER(QDir::homePath() + "/triage"); const QString DACA2_PACKAGES(QDir::homePath() + "/daca2-packages"); -const int MAX_ERRORS = 100; +constexpr int MAX_ERRORS = 100; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),