fixed some "Variable can be made constexpr" Rider warnings (#5615)

This commit is contained in:
Oliver Stöneberg 2023-11-03 09:55:44 +01:00 committed by GitHub
parent 9280b5d7a5
commit 63e00ea918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 600 additions and 600 deletions

View File

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

View File

@ -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

View File

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

View File

@ -57,12 +57,12 @@
#include <QVariant>
#include <QtCore>
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)
{

View File

@ -60,25 +60,25 @@
#include <QVariantMap>
#include <Qt>
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)

View File

@ -240,7 +240,7 @@ protected:
private:
void manageStyleControls();
static const int mLangCodeRole = Qt::UserRole;
static constexpr int mLangCodeRole = Qt::UserRole;
bool mPremium;
};

View File

@ -29,8 +29,8 @@
#include <QStringRef>
#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)

View File

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

View File

@ -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)

View File

@ -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<std::pair<std::string, std::string>, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}};
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,
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);

View File

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

View File

@ -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) + "..");

View File

@ -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;

View File

@ -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;

View File

@ -39,21 +39,21 @@
#include <tinyxml2.h>
//---------------------------------------------------------------------------
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;

View File

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

View File

@ -171,7 +171,7 @@ void Summaries::loadReturn(const std::string &buildDir, std::set<std::string> &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<std::string> call = getSummaryData(line, "call");

View File

@ -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

View File

@ -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) :

View File

@ -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<ValueFlow::Value> values = getIteratorValues(tok->astOperand1()->values(), &kind);
if (!values.empty()) {
cond.vartok = tok->astOperand2();

View File

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

View File

@ -3597,17 +3597,17 @@ private:
}
void buffer_overrun_readSizeFromCfg() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"u8\" sign=\"u\" size=\"1\"/>\n"
" <function name=\"mystrcpy\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"strlen\" arg=\"2\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"u8\" sign=\"u\" size=\"1\"/>\n"
" <function name=\"mystrcpy\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"strlen\" arg=\"2\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" </function>\n"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mymemset\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"argvalue\" arg=\"3\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" <arg nr=\"3\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mymemset\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"argvalue\" arg=\"3\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" <arg nr=\"3\"/>\n"
" </function>\n"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mystrncpy\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"strlen\" arg=\"2\"/>\n"
" <minsize type=\"argvalue\" arg=\"3\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" <arg nr=\"3\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mystrncpy\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"strlen\" arg=\"2\"/>\n"
" <minsize type=\"argvalue\" arg=\"3\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" <arg nr=\"3\"/>\n"
" </function>\n"
"</def>";
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
check("void f() {\n"
@ -4346,19 +4346,19 @@ private:
}
void minsize_strlen() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mysprintf\">\n"
" <noreturn>false</noreturn>\n"
" <formatstr/>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"strlen\" arg=\"2\"/>\n"
" </arg>\n"
" <arg nr=\"2\">\n"
" <formatstr/>\n"
" </arg>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mysprintf\">\n"
" <noreturn>false</noreturn>\n"
" <formatstr/>\n"
" <arg nr=\"1\">\n"
" <minsize type=\"strlen\" arg=\"2\"/>\n"
" </arg>\n"
" <arg nr=\"2\">\n"
" <formatstr/>\n"
" </arg>\n"
" </function>\n"
"</def>";
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
// formatstr..
@ -4459,17 +4459,17 @@ private:
}
void minsize_mul() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"myfread\">\n"
" <arg nr=\"1\">\n"
" <minsize type=\"mul\" arg=\"2\" arg2=\"3\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" <arg nr=\"3\"/>\n"
" <arg nr=\"4\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"myfread\">\n"
" <arg nr=\"1\">\n"
" <minsize type=\"mul\" arg=\"2\" arg2=\"3\"/>\n"
" </arg>\n"
" <arg nr=\"2\"/>\n"
" <arg nr=\"3\"/>\n"
" <arg nr=\"4\"/>\n"
" </function>\n"
"</def>";
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
check("void f() {\n"

View File

@ -3444,11 +3444,11 @@ private:
}
void memsetOnStdPodType() { // Ticket #5901
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"std::uint8_t\" sign=\"u\" size=\"1\"/>\n"
" <podtype name=\"std::atomic_bool\"/>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"std::uint8_t\" sign=\"u\" size=\"1\"/>\n"
" <podtype name=\"std::atomic_bool\"/>\n"
"</def>";
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
checkNoMemset("class A {\n"

View File

@ -1296,14 +1296,14 @@ private:
}
void checkIgnoredReturnValue() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def version=\"2\">\n"
" <function name=\"mystrcmp,foo::mystrcmp\">\n"
" <use-retval/>\n"
" <arg nr=\"1\"/>\n"
" <arg nr=\"2\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def version=\"2\">\n"
" <function name=\"mystrcmp,foo::mystrcmp\">\n"
" <use-retval/>\n"
" <arg nr=\"1\"/>\n"
" <arg nr=\"2\"/>\n"
" </function>\n"
"</def>";
const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata, sizeof(xmldata)).build();
check("void foo() {\n"

View File

@ -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[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<project version=\"1\">\n"
" <root name=\".\"/>\n"
" <builddir>out1</builddir>\n"
" <analyze-all-vs-configs>true</analyze-all-vs-configs>\n"
" <includedir>\n"
" <dir name=\"lib/\"/>\n"
" </includedir>\n"
" <paths>\n"
" <dir name=\"cli/\"/>\n"
" </paths>\n"
" <exclude>\n"
" <path name=\"gui/temp/\"/>\n"
" </exclude>\n"
" <project-name>test test</project-name>\n"
"</project>\n";
constexpr char xml[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<project version=\"1\">\n"
" <root name=\".\"/>\n"
" <builddir>out1</builddir>\n"
" <analyze-all-vs-configs>true</analyze-all-vs-configs>\n"
" <includedir>\n"
" <dir name=\"lib/\"/>\n"
" </includedir>\n"
" <paths>\n"
" <dir name=\"cli/\"/>\n"
" </paths>\n"
" <exclude>\n"
" <path name=\"gui/temp/\"/>\n"
" </exclude>\n"
" <project-name>test test</project-name>\n"
"</project>\n";
std::istringstream istr(xml);
Settings s;
TestImporter project;

View File

@ -39,28 +39,28 @@ private:
Settings settings;
void run() override {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
" <memory>\n"
" <alloc>malloc</alloc>\n"
" <realloc>realloc</realloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
" <resource>\n"
" <alloc>socket</alloc>\n"
" <dealloc>close</dealloc>\n"
" </resource>\n"
" <resource>\n"
" <alloc>fopen</alloc>\n"
" <realloc realloc-arg=\"3\">freopen</realloc>\n"
" <dealloc>fclose</dealloc>\n"
" </resource>\n"
" <smart-pointer class-name=\"std::shared_ptr\"/>\n"
" <smart-pointer class-name=\"std::unique_ptr\">\n"
" <unique/>\n"
" </smart-pointer>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
" <memory>\n"
" <alloc>malloc</alloc>\n"
" <realloc>realloc</realloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
" <resource>\n"
" <alloc>socket</alloc>\n"
" <dealloc>close</dealloc>\n"
" </resource>\n"
" <resource>\n"
" <alloc>fopen</alloc>\n"
" <realloc realloc-arg=\"3\">freopen</realloc>\n"
" <dealloc>fclose</dealloc>\n"
" </resource>\n"
" <smart-pointer class-name=\"std::shared_ptr\"/>\n"
" <smart-pointer class-name=\"std::unique_ptr\">\n"
" <unique/>\n"
" </smart-pointer>\n"
"</def>";
settings = settingsBuilder(settings).libraryxml(xmldata, sizeof(xmldata)).build();
// Assign
@ -2777,18 +2777,18 @@ private:
}
void functionCallCastConfig() { // #9652
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"2\">\n"
" <function name=\"free_func\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <not-uninit/>\n"
" </arg>\n"
" <arg nr=\"2\">\n"
" <not-uninit/>\n"
" </arg>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"2\">\n"
" <function name=\"free_func\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\">\n"
" <not-uninit/>\n"
" </arg>\n"
" <arg nr=\"2\">\n"
" <not-uninit/>\n"
" </arg>\n"
" </function>\n"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"2\">\n"
" <function name=\"SomeClass::someMethod\">\n"
" <leak-ignore/>\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\" direction=\"in\"/>\n"
" </function>\n"
"</def>\n";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"2\">\n"
" <function name=\"SomeClass::someMethod\">\n"
" <leak-ignore/>\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\" direction=\"in\"/>\n"
" </function>\n"
"</def>\n";
const Settings settingsLeakIgnore = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
check("void f() {\n"
" double* a = new double[1024];\n"

View File

@ -102,19 +102,19 @@ private:
void empty() const {
// Reading an empty library file is considered to be OK
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
ASSERT(library.functions.empty());
}
void function() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <noreturn>false</noreturn>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <noreturn>false</noreturn>\n"
" </function>\n"
"</def>";
TokenList tokenList(nullptr);
std::istringstream istr("foo();");
@ -129,12 +129,12 @@ private:
}
void function_match_scope() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -155,12 +155,12 @@ private:
}
void function_match_args() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" </function>\n"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" <arg nr=\"2\" default=\"0\"/>"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" <arg nr=\"2\" default=\"0\"/>"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -224,12 +224,12 @@ private:
}
void function_match_var() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"/>"
" </function>\n"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"><not-uninit/></arg>\n"
" <arg nr=\"2\"><not-null/></arg>\n"
" <arg nr=\"3\"><formatstr/></arg>\n"
" <arg nr=\"4\"><strz/></arg>\n"
" <arg nr=\"5\" default=\"0\"><not-bool/></arg>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"><not-uninit/></arg>\n"
" <arg nr=\"2\"><not-null/></arg>\n"
" <arg nr=\"3\"><formatstr/></arg>\n"
" <arg nr=\"4\"><strz/></arg>\n"
" <arg nr=\"5\" default=\"0\"><not-bool/></arg>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -266,12 +266,12 @@ private:
}
void function_arg_any() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"<function name=\"foo\">\n"
" <arg nr=\"any\"><not-uninit/></arg>\n"
"</function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"<function name=\"foo\">\n"
" <arg nr=\"any\"><not-uninit/></arg>\n"
"</function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -279,13 +279,13 @@ private:
}
void function_arg_variadic() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"<function name=\"foo\">\n"
" <arg nr=\"1\"></arg>\n"
" <arg nr=\"variadic\"><not-uninit/></arg>\n"
"</function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"<function name=\"foo\">\n"
" <arg nr=\"1\"></arg>\n"
" <arg nr=\"variadic\"><not-uninit/></arg>\n"
"</function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -303,15 +303,15 @@ private:
}
void function_arg_direction() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"<function name=\"foo\">\n"
" <arg nr=\"1\" direction=\"in\"></arg>\n"
" <arg nr=\"2\" direction=\"out\"></arg>\n"
" <arg nr=\"3\" direction=\"inout\"></arg>\n"
" <arg nr=\"4\"></arg>\n"
"</function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"<function name=\"foo\">\n"
" <arg nr=\"1\" direction=\"in\"></arg>\n"
" <arg nr=\"2\" direction=\"out\"></arg>\n"
" <arg nr=\"3\" direction=\"inout\"></arg>\n"
" <arg nr=\"4\"></arg>\n"
"</function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -328,22 +328,22 @@ private:
}
void function_arg_valid() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"><valid>1:</valid></arg>\n"
" <arg nr=\"2\"><valid>-7:0</valid></arg>\n"
" <arg nr=\"3\"><valid>1:5,8</valid></arg>\n"
" <arg nr=\"4\"><valid>-1,5</valid></arg>\n"
" <arg nr=\"5\"><valid>:1,5</valid></arg>\n"
" <arg nr=\"6\"><valid>1.5:</valid></arg>\n"
" <arg nr=\"7\"><valid>-6.7:-5.5,-3.3:-2.7</valid></arg>\n"
" <arg nr=\"8\"><valid>0.0:</valid></arg>\n"
" <arg nr=\"9\"><valid>:2.0</valid></arg>\n"
" <arg nr=\"10\"><valid>0.0</valid></arg>\n"
" <arg nr=\"11\"><valid>!0.0</valid></arg>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"><valid>1:</valid></arg>\n"
" <arg nr=\"2\"><valid>-7:0</valid></arg>\n"
" <arg nr=\"3\"><valid>1:5,8</valid></arg>\n"
" <arg nr=\"4\"><valid>-1,5</valid></arg>\n"
" <arg nr=\"5\"><valid>:1,5</valid></arg>\n"
" <arg nr=\"6\"><valid>1.5:</valid></arg>\n"
" <arg nr=\"7\"><valid>-6.7:-5.5,-3.3:-2.7</valid></arg>\n"
" <arg nr=\"8\"><valid>0.0:</valid></arg>\n"
" <arg nr=\"9\"><valid>:2.0</valid></arg>\n"
" <arg nr=\"10\"><valid>0.0</valid></arg>\n"
" <arg nr=\"11\"><valid>!0.0</valid></arg>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -476,16 +476,16 @@ private:
}
void function_arg_minsize() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"><minsize type=\"strlen\" arg=\"2\"/></arg>\n"
" <arg nr=\"2\"><minsize type=\"argvalue\" arg=\"3\"/></arg>\n"
" <arg nr=\"3\"/>\n"
" <arg nr=\"4\"><minsize type=\"value\" value=\"500\"/></arg>\n"
" <arg nr=\"5\"><minsize type=\"value\" value=\"4\" baseType=\"int\"/></arg>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"foo\">\n"
" <arg nr=\"1\"><minsize type=\"strlen\" arg=\"2\"/></arg>\n"
" <arg nr=\"2\"><minsize type=\"argvalue\" arg=\"3\"/></arg>\n"
" <arg nr=\"3\"/>\n"
" <arg nr=\"4\"><minsize type=\"value\" value=\"500\"/></arg>\n"
" <arg nr=\"5\"><minsize type=\"value\" value=\"4\" baseType=\"int\"/></arg>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -539,12 +539,12 @@ private:
}
void function_namespace() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"Foo::foo,bar\">\n"
" <noreturn>false</noreturn>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"Foo::foo,bar\">\n"
" <noreturn>false</noreturn>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -568,12 +568,12 @@ private:
}
void function_method() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"CString::Format\">\n"
" <noreturn>false</noreturn>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"CString::Format\">\n"
" <noreturn>false</noreturn>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -595,12 +595,12 @@ private:
}
void function_baseClassMethod() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"Base::f\">\n"
" <arg nr=\"1\"><not-null/></arg>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"Base::f\">\n"
" <arg nr=\"1\"><not-null/></arg>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -621,15 +621,15 @@ private:
}
void function_warn() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"a\">\n"
" <warn severity=\"style\" cstd=\"c99\">Message</warn>\n"
" </function>\n"
" <function name=\"b\">\n"
" <warn severity=\"performance\" cppstd=\"c++11\" reason=\"Obsolescent\" alternatives=\"c,d,e\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"a\">\n"
" <warn severity=\"style\" cstd=\"c99\">Message</warn>\n"
" </function>\n"
" <function name=\"b\">\n"
" <warn severity=\"performance\" cppstd=\"c++11\" reason=\"Obsolescent\" alternatives=\"c,d,e\"/>\n"
" </function>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -657,13 +657,13 @@ private:
}
void memory() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>CreateX</alloc>\n"
" <dealloc>DeleteX</dealloc>\n"
" </memory>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>CreateX</alloc>\n"
" <dealloc>DeleteX</dealloc>\n"
" </memory>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -677,20 +677,20 @@ private:
ASSERT(df && df->arg == 1);
}
void memory2() const {
const char xmldata1[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>malloc</alloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
"</def>";
const char xmldata2[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>foo</alloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
"</def>";
constexpr char xmldata1[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>malloc</alloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
"</def>";
constexpr char xmldata2[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>foo</alloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc arg=\"5\" init=\"false\">CreateX</alloc>\n"
" <dealloc arg=\"2\">DeleteX</dealloc>\n"
" </memory>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc arg=\"5\" init=\"false\">CreateX</alloc>\n"
" <dealloc arg=\"2\">DeleteX</dealloc>\n"
" </memory>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -719,13 +719,13 @@ private:
}
void resource() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <resource>\n"
" <alloc>CreateX</alloc>\n"
" <dealloc>DeleteX</dealloc>\n"
" </resource>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <resource>\n"
" <alloc>CreateX</alloc>\n"
" <dealloc>DeleteX</dealloc>\n"
" </resource>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -737,13 +737,13 @@ private:
void podtype() const {
{
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"s8\" sign=\"s\" size=\"1\"/>\n"
" <podtype name=\"u8\" sign=\"u\" size=\"1\"/>\n"
" <podtype name=\"u16\" sign=\"u\" size=\"2\"/>\n"
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"s8\" sign=\"s\" size=\"1\"/>\n"
" <podtype name=\"u8\" sign=\"u\" size=\"1\"/>\n"
" <podtype name=\"u16\" sign=\"u\" size=\"2\"/>\n"
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
// s8
@ -791,37 +791,37 @@ private:
}
void container() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <container id=\"A\" startPattern=\"std :: A &lt;\" endPattern=\"&gt; !!::\" itEndPattern=\"&gt; :: iterator\">\n"
" <type templateParameter=\"1\"/>\n"
" <size templateParameter=\"4\">\n"
" <function name=\"resize\" action=\"resize\"/>\n"
" <function name=\"clear\" action=\"clear\"/>\n"
" <function name=\"size\" yields=\"size\"/>\n"
" <function name=\"empty\" yields=\"empty\"/>\n"
" <function name=\"push_back\" action=\"push\"/>\n"
" <function name=\"pop_back\" action=\"pop\"/>\n"
" </size>\n"
" <access>\n"
" <function name=\"at\" yields=\"at_index\"/>\n"
" <function name=\"begin\" yields=\"start-iterator\"/>\n"
" <function name=\"end\" yields=\"end-iterator\"/>\n"
" <function name=\"data\" yields=\"buffer\"/>\n"
" <function name=\"c_str\" yields=\"buffer-nt\"/>\n"
" <function name=\"front\" yields=\"item\"/>\n"
" <function name=\"find\" action=\"find\"/>\n"
" <function name=\"cfind\" action=\"find-const\"/>\n"
" </access>\n"
" </container>\n"
" <container id=\"B\" startPattern=\"std :: B &lt;\" inherits=\"A\" opLessAllowed=\"false\">\n"
" <size templateParameter=\"3\"/>\n" // Inherits all but templateParameter
" </container>\n"
" <container id=\"C\">\n"
" <type string=\"std-like\"/>\n"
" <access indexOperator=\"array-like\"/>\n"
" </container>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <container id=\"A\" startPattern=\"std :: A &lt;\" endPattern=\"&gt; !!::\" itEndPattern=\"&gt; :: iterator\">\n"
" <type templateParameter=\"1\"/>\n"
" <size templateParameter=\"4\">\n"
" <function name=\"resize\" action=\"resize\"/>\n"
" <function name=\"clear\" action=\"clear\"/>\n"
" <function name=\"size\" yields=\"size\"/>\n"
" <function name=\"empty\" yields=\"empty\"/>\n"
" <function name=\"push_back\" action=\"push\"/>\n"
" <function name=\"pop_back\" action=\"pop\"/>\n"
" </size>\n"
" <access>\n"
" <function name=\"at\" yields=\"at_index\"/>\n"
" <function name=\"begin\" yields=\"start-iterator\"/>\n"
" <function name=\"end\" yields=\"end-iterator\"/>\n"
" <function name=\"data\" yields=\"buffer\"/>\n"
" <function name=\"c_str\" yields=\"buffer-nt\"/>\n"
" <function name=\"front\" yields=\"item\"/>\n"
" <function name=\"find\" action=\"find\"/>\n"
" <function name=\"cfind\" action=\"find-const\"/>\n"
" </access>\n"
" </container>\n"
" <container id=\"B\" startPattern=\"std :: B &lt;\" inherits=\"A\" opLessAllowed=\"false\">\n"
" <size templateParameter=\"3\"/>\n" // Inherits all but templateParameter
" </container>\n"
" <container id=\"C\">\n"
" <type string=\"std-like\"/>\n"
" <access indexOperator=\"array-like\"/>\n"
" </container>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
@ -936,23 +936,23 @@ private:
void version() const {
{
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
}
{
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"1\">\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"1\">\n"
"</def>";
Library library;
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
}
{
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"42\">\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"42\">\n"
"</def>";
Library library;
const Library::Error err = readLibrary(library, xmldata);
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::UNSUPPORTED_FORMAT);

View File

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

View File

@ -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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"exit\">\n"
" <noreturn>true</noreturn>\n"
" <arg nr=\"1\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"exit\">\n"
" <noreturn>true</noreturn>\n"
" <arg nr=\"1\"/>\n"
" </function>\n"
"</def>";
Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
check("void foo() {\n"
@ -6391,14 +6391,14 @@ private:
}
void duplicateExpression3() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mystrcmp\">\n"
" <pure/>\n"
" <arg nr=\"1\"/>\n"
" <arg nr=\"2\"/>\n"
" </function>\n"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"mystrcmp\">\n"
" <pure/>\n"
" <arg nr=\"1\"/>\n"
" <arg nr=\"2\"/>\n"
" </function>\n"
"</def>";
Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
check("void foo() {\n"

View File

@ -55,7 +55,7 @@ private:
void empty() const {
// An empty platform file does not change values, only the type.
const char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
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[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>8</char_bit>\n"
" <default-sign>unsigned</default-sign>\n"
" <sizeof>\n"
" <bool>1</bool>\n"
" <short>2</short>\n"
" <int>2</int>\n"
" <long>4</long>\n"
" <long-long>8</long-long>\n"
" <float>4</float>\n"
" <double>4</double>\n"
" <long-double>4</long-double>\n"
" <pointer>2</pointer>\n"
" <size_t>2</size_t>\n"
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>8</char_bit>\n"
" <default-sign>unsigned</default-sign>\n"
" <sizeof>\n"
" <bool>1</bool>\n"
" <short>2</short>\n"
" <int>2</int>\n"
" <long>4</long>\n"
" <long-long>8</long-long>\n"
" <float>4</float>\n"
" <double>4</double>\n"
" <long-double>4</long-double>\n"
" <pointer>2</pointer>\n"
" <size_t>2</size_t>\n"
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
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[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>20</char_bit>\n"
" <default-sign>signed</default-sign>\n"
" <sizeof>\n"
" <bool>1</bool>\n"
" <short>2</short>\n"
" <int>3</int>\n"
" <long>4</long>\n"
" <long-long>5</long-long>\n"
" <float>6</float>\n"
" <double>7</double>\n"
" <long-double>8</long-double>\n"
" <pointer>9</pointer>\n"
" <size_t>10</size_t>\n"
" <wchar_t>11</wchar_t>\n"
" </sizeof>\n"
" </platform>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>20</char_bit>\n"
" <default-sign>signed</default-sign>\n"
" <sizeof>\n"
" <bool>1</bool>\n"
" <short>2</short>\n"
" <int>3</int>\n"
" <long>4</long>\n"
" <long-long>5</long-long>\n"
" <float>6</float>\n"
" <double>7</double>\n"
" <long-double>8</long-double>\n"
" <pointer>9</pointer>\n"
" <size_t>10</size_t>\n"
" <wchar_t>11</wchar_t>\n"
" </sizeof>\n"
" </platform>";
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[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit1>8</char_bit1>\n"
" <default-sign1>unsigned</default-sign1>\n"
" <sizeof1>\n"
" <bool1>1</bool1>\n"
" <short1>2</short1>\n"
" <int1>3</int1>\n"
" <long1>4</long1>\n"
" <long-long1>5</long-long1>\n"
" <float1>6</float1>\n"
" <double1>7</double1>\n"
" <long-double1>8</long-double1>\n"
" <pointer1>9</pointer1>\n"
" <size_t1>10</size_t1>\n"
" <wchar_t1>11</wchar_t1>\n"
" </sizeof1>\n"
" </platform>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit1>8</char_bit1>\n"
" <default-sign1>unsigned</default-sign1>\n"
" <sizeof1>\n"
" <bool1>1</bool1>\n"
" <short1>2</short1>\n"
" <int1>3</int1>\n"
" <long1>4</long1>\n"
" <long-long1>5</long-long1>\n"
" <float1>6</float1>\n"
" <double1>7</double1>\n"
" <long-double1>8</long-double1>\n"
" <pointer1>9</pointer1>\n"
" <size_t1>10</size_t1>\n"
" <wchar_t1>11</wchar_t1>\n"
" </sizeof1>\n"
" </platform>";
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[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>0</char_bit>\n"
" <default-sign>z</default-sign>\n"
" <sizeof>\n"
" <bool>0</bool>\n"
" <short>0</short>\n"
" <int>0</int>\n"
" <long>0</long>\n"
" <long-long>0</long-long>\n"
" <float>0</float>\n"
" <double>0</double>\n"
" <long-double>0</long-double>\n"
" <pointer>0</pointer>\n"
" <size_t>0</size_t>\n"
" <wchar_t>0</wchar_t>\n"
" </sizeof>\n"
" </platform>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>0</char_bit>\n"
" <default-sign>z</default-sign>\n"
" <sizeof>\n"
" <bool>0</bool>\n"
" <short>0</short>\n"
" <int>0</int>\n"
" <long>0</long>\n"
" <long-long>0</long-long>\n"
" <float>0</float>\n"
" <double>0</double>\n"
" <long-double>0</long-double>\n"
" <pointer>0</pointer>\n"
" <size_t>0</size_t>\n"
" <wchar_t>0</wchar_t>\n"
" </sizeof>\n"
" </platform>";
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[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>8</char_bit>\n"
" <default-sign>unsigned</default-sign>\n"
" <sizeof>\n"
" <boolt>1</bool>\n"
" <short>2</short>\n"
" <int>2</int>\n"
" <long>4</long>\n"
" <long-long>8</long-long>\n"
" <float>4</float>\n"
" <double>4</double>\n"
" <long-double>4</long-double>\n"
" <pointer>2</pointer>\n"
" <size_t>2</size_t>\n"
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>8</char_bit>\n"
" <default-sign>unsigned</default-sign>\n"
" <sizeof>\n"
" <boolt>1</bool>\n"
" <short>2</short>\n"
" <int>2</int>\n"
" <long>4</long>\n"
" <long-long>8</long-long>\n"
" <float>4</float>\n"
" <double>4</double>\n"
" <long-double>4</long-double>\n"
" <pointer>2</pointer>\n"
" <size_t>2</size_t>\n"
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
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[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit></char_bit>\n"
" <default-sign></default-sign>\n"
" <sizeof>\n"
" <bool></bool>\n"
" <short></short>\n"
" <int></int>\n"
" <long></long>\n"
" <long-long></long-long>\n"
" <float></float>\n"
" <double></double>\n"
" <long-double></long-double>\n"
" <pointer></pointer>\n"
" <size_t></size_t>\n"
" <wchar_t></wchar_t>\n"
" </sizeof>\n"
" </platform>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit></char_bit>\n"
" <default-sign></default-sign>\n"
" <sizeof>\n"
" <bool></bool>\n"
" <short></short>\n"
" <int></int>\n"
" <long></long>\n"
" <long-long></long-long>\n"
" <float></float>\n"
" <double></double>\n"
" <long-double></long-double>\n"
" <pointer></pointer>\n"
" <size_t></size_t>\n"
" <wchar_t></wchar_t>\n"
" </sizeof>\n"
" </platform>";
Platform platform;
ASSERT(!readPlatform(platform, xmldata));
}

View File

@ -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;

View File

@ -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";

View File

@ -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;

View File

@ -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";

View File

@ -833,10 +833,10 @@ private:
{
// Ticket #6701 - Variable name is a POD type according to cfg
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"1\">"
" <podtype name=\"_tm\"/>"
"</def>";
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"1\">"
" <podtype name=\"_tm\"/>"
"</def>";
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[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"uninitvar_funcArgInTest\">\n"
" <arg nr=\"1\" direction=\"in\"/>\n"
" </function>\n"
" <function name=\"uninitvar_funcArgOutTest\">\n"
" <arg nr=\"1\" direction=\"out\"/>\n"
" </function>\n"
"</def>";
constexpr char argDirectionsTestXmlData[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"uninitvar_funcArgInTest\">\n"
" <arg nr=\"1\" direction=\"in\"/>\n"
" </function>\n"
" <function name=\"uninitvar_funcArgOutTest\">\n"
" <arg nr=\"1\" direction=\"out\"/>\n"
" </function>\n"
"</def>";
const Settings s = settingsBuilder(settings).libraryxml(argDirectionsTestXmlData, sizeof(argDirectionsTestXmlData)).build();
checkUninitVar("struct AB { int a; };\n"

View File

@ -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"

View File

@ -46,11 +46,11 @@ private:
void run() override {
// strcpy, abort cfg
const char cfg[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"strcpy\"> <arg nr=\"1\"><not-null/></arg> </function>\n"
" <function name=\"abort\"> <noreturn>true</noreturn> </function>\n" // abort is a noreturn function
"</def>";
constexpr char cfg[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"strcpy\"> <arg nr=\"1\"><not-null/></arg> </function>\n"
" <function name=\"abort\"> <noreturn>true</noreturn> </function>\n" // abort is a noreturn function
"</def>";
settings = settingsBuilder(settings).libraryxml(cfg, sizeof(cfg)).build();
TEST_CASE(valueFlowNumber);

View File

@ -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 "

View File

@ -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),