Skip to content

Commit 63e00ea

Browse files
authored
fixed some "Variable can be made constexpr" Rider warnings (cppcheck-opensource#5615)
1 parent 9280b5d commit 63e00ea

39 files changed

Lines changed: 600 additions & 600 deletions

cli/cppcheckexecutorsig.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151

5252
// 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
5353
#ifdef __USE_DYNAMIC_STACK_SIZE
54-
static const size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer
54+
static constexpr size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer
5555
#else
56-
static const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
56+
static constexpr size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
5757
#endif
5858
static char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler
5959
static bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper()

cli/stacktrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool lowMem)
3535
const int fd = fileno(output);
3636
void *callstackArray[32]= {nullptr}; // the less resources the better...
3737
const int currentdepth = backtrace(callstackArray, (int)getArrayLength(callstackArray));
38-
const int offset=2; // some entries on top are within our own exception handling code or libc
38+
constexpr int offset=2; // some entries on top are within our own exception handling code or libc
3939
if (maxdepth<0)
4040
maxdepth=currentdepth-offset;
4141
else

gui/mainwindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,14 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
271271
mUI->mActionEnforceCpp->setActionGroup(mSelectLanguageActions);
272272
mUI->mActionAutoDetectLanguage->setActionGroup(mSelectLanguageActions);
273273

274+
// TODO: we no longer default to a Windows platform in CLI - so we should probably also get rid of this in the GUI
274275
// For Windows platforms default to Win32 checked platform.
275276
// For other platforms default to unspecified/default which means the
276277
// platform Cppcheck GUI was compiled on.
277278
#if defined(_WIN32)
278-
const Platform::Type defaultPlatform = Platform::Type::Win32W;
279+
constexpr Platform::Type defaultPlatform = Platform::Type::Win32W;
279280
#else
280-
const Platform::Type defaultPlatform = Platform::Type::Unspecified;
281+
constexpr Platform::Type defaultPlatform = Platform::Type::Unspecified;
281282
#endif
282283
PlatformData &platform = mPlatforms.get((Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
283284
platform.mActMainWindow->setChecked(true);

gui/projectfiledialog.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
#include <QVariant>
5858
#include <QtCore>
5959

60-
static const char ADDON_MISRA[] = "misra";
61-
static const char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023";
62-
static const char CODING_STANDARD_MISRA_CPP_2008[] = "misra-cpp-2008";
63-
static const char CODING_STANDARD_CERT_C[] = "cert-c-2016";
64-
static const char CODING_STANDARD_CERT_CPP[] = "cert-cpp-2016";
65-
static const char CODING_STANDARD_AUTOSAR[] = "autosar";
60+
static constexpr char ADDON_MISRA[] = "misra";
61+
static constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023";
62+
static constexpr char CODING_STANDARD_MISRA_CPP_2008[] = "misra-cpp-2008";
63+
static constexpr char CODING_STANDARD_CERT_C[] = "cert-c-2016";
64+
static constexpr char CODING_STANDARD_CERT_CPP[] = "cert-cpp-2016";
65+
static constexpr char CODING_STANDARD_AUTOSAR[] = "autosar";
6666

6767
/** Return paths from QListWidget */
6868
static QStringList getPaths(const QListWidget *list)
@@ -77,7 +77,7 @@ static QStringList getPaths(const QListWidget *list)
7777
}
7878

7979
/** Platforms shown in the platform combobox */
80-
static const Platform::Type builtinPlatforms[] = {
80+
static constexpr Platform::Type builtinPlatforms[] = {
8181
Platform::Type::Native,
8282
Platform::Type::Win32A,
8383
Platform::Type::Win32W,
@@ -86,7 +86,7 @@ static const Platform::Type builtinPlatforms[] = {
8686
Platform::Type::Unix64
8787
};
8888

89-
static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]);
89+
static constexpr int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]);
9090

9191
QStringList ProjectFileDialog::getProjectConfigs(const QString &fileName)
9292
{

gui/resultstree.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@
6060
#include <QVariantMap>
6161
#include <Qt>
6262

63-
static const char COLUMN[] = "column";
64-
static const char CWE[] = "cwe";
65-
static const char ERRORID[] = "id";
66-
static const char FILENAME[] = "file";
67-
static const char FILE0[] = "file0";
68-
static const char HASH[] = "hash";
69-
static const char HIDE[] = "hide";
70-
static const char INCONCLUSIVE[] = "inconclusive";
71-
static const char LINE[] = "line";
72-
static const char MESSAGE[] = "message";
73-
static const char SEVERITY[] = "severity";
74-
static const char SINCEDATE[] = "sinceDate";
75-
static const char SYMBOLNAMES[] = "symbolNames";
76-
static const char SUMMARY[] = "summary";
77-
static const char TAGS[] = "tags";
63+
static constexpr char COLUMN[] = "column";
64+
static constexpr char CWE[] = "cwe";
65+
static constexpr char ERRORID[] = "id";
66+
static constexpr char FILENAME[] = "file";
67+
static constexpr char FILE0[] = "file0";
68+
static constexpr char HASH[] = "hash";
69+
static constexpr char HIDE[] = "hide";
70+
static constexpr char INCONCLUSIVE[] = "inconclusive";
71+
static constexpr char LINE[] = "line";
72+
static constexpr char MESSAGE[] = "message";
73+
static constexpr char SEVERITY[] = "severity";
74+
static constexpr char SINCEDATE[] = "sinceDate";
75+
static constexpr char SYMBOLNAMES[] = "symbolNames";
76+
static constexpr char SUMMARY[] = "summary";
77+
static constexpr char TAGS[] = "tags";
7878

7979
// These must match column headers given in ResultsTree::translate()
80-
static const int COLUMN_SINCE_DATE = 6;
81-
static const int COLUMN_TAGS = 7;
80+
static constexpr int COLUMN_SINCE_DATE = 6;
81+
static constexpr int COLUMN_TAGS = 7;
8282

8383
ResultsTree::ResultsTree(QWidget * parent) :
8484
QTreeView(parent)

gui/settingsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ protected slots:
240240
private:
241241
void manageStyleControls();
242242

243-
static const int mLangCodeRole = Qt::UserRole;
243+
static constexpr int mLangCodeRole = Qt::UserRole;
244244

245245
bool mPremium;
246246
};

gui/xmlreport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include <QStringRef>
3030
#endif
3131

32-
static const char ResultElementName[] = "results";
33-
static const char VersionAttribute[] = "version";
32+
static constexpr char ResultElementName[] = "results";
33+
static constexpr char VersionAttribute[] = "version";
3434

3535
XmlReport::XmlReport(const QString &filename) :
3636
Report(filename)

lib/calculate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr)
5252
auto wrap = [](T z) {
5353
return R{z};
5454
};
55-
const MathLib::bigint maxBitsShift = sizeof(MathLib::bigint) * 8;
55+
constexpr MathLib::bigint maxBitsShift = sizeof(MathLib::bigint) * 8;
5656
// For portability we cannot shift signed integers by 63 bits
57-
const MathLib::bigint maxBitsSignedShift = maxBitsShift - 1;
57+
constexpr MathLib::bigint maxBitsSignedShift = maxBitsShift - 1;
5858
switch (MathLib::encodeMultiChar(s)) {
5959
case '+':
6060
return wrap(x + y);

lib/checkclass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,7 @@ void CheckClass::missingMemberCopyError(const Token *tok, Function::Type functio
11171117
const std::string message =
11181118
"$symbol:" + classname + "::" + varname + "\n" +
11191119
"Member variable '$symbol' is not assigned in the " + ctor + " constructor. Should it be " + action;
1120-
const char id[] = "missingMemberCopy";
1121-
reportError(tok, Severity::warning, id, message, CWE398, Certainty::inconclusive);
1120+
reportError(tok, Severity::warning, "missingMemberCopy", message, CWE398, Certainty::inconclusive);
11221121
}
11231122

11241123
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname, bool inconclusive)

lib/checkleakautovar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static const CWE CWE672(672U);
5454
static const CWE CWE415(415U);
5555

5656
// Hardcoded allocation types (not from library)
57-
static const int NEW_ARRAY = -2;
58-
static const int NEW = -1;
57+
static constexpr int NEW_ARRAY = -2;
58+
static constexpr int NEW = -1;
5959

6060
static const std::array<std::pair<std::string, std::string>, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}};
6161
static const std::array<std::pair<std::string, std::string>, 4> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}};
@@ -304,9 +304,9 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
304304
static const nonneg int recursiveLimit = 300;
305305
#elif defined(__MINGW32__)
306306
// testrunner crashes with stack overflow in CI
307-
static const nonneg int recursiveLimit = 600;
307+
static constexpr nonneg int recursiveLimit = 600;
308308
#else
309-
static const nonneg int recursiveLimit = 1000;
309+
static constexpr nonneg int recursiveLimit = 1000;
310310
#endif
311311
if (++recursiveCount > recursiveLimit) // maximum number of "else if ()"
312312
throw InternalError(startToken, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached.", InternalError::LIMIT);

0 commit comments

Comments
 (0)