diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index f941db2ab..b5306b80b 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3111,8 +3111,7 @@ private: } void countSprintfLength() const { - std::list unknownParameter; - unknownParameter.push_back(0); + std::list unknownParameter(1, nullptr); ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("Hello", unknownParameter)); ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength("s", unknownParameter)); @@ -3134,8 +3133,7 @@ private: ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength("%%%%%d", unknownParameter)); Token strTok(0); - std::list stringAsParameter; - stringAsParameter.push_back(&strTok); + std::list stringAsParameter(1, &strTok); strTok.str("\"\""); ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength("str%s", stringAsParameter)); strTok.str("\"12345\""); @@ -3149,10 +3147,9 @@ private: ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%5.6s", stringAsParameter)); ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength("%6.6s", stringAsParameter)); - std::list intAsParameter; Token numTok(0); numTok.str("12345"); - intAsParameter.push_back(&numTok); + std::list intAsParameter(1, &numTok); ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%02ld", intAsParameter)); ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%08ld", intAsParameter)); ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%.2d", intAsParameter)); @@ -3165,26 +3162,21 @@ private: ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%1.5x", intAsParameter)); ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%5.1x", intAsParameter)); - std::list floatAsParameter; Token floatTok(0); floatTok.str("1.12345f"); - floatAsParameter.push_back(&floatTok); + std::list floatAsParameter(1, &floatTok); TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength("%.2f", floatAsParameter)); ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%8.2f", floatAsParameter)); TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength("%2.2f", floatAsParameter)); - std::list floatAsParameter2; Token floatTok2(0); floatTok2.str("100.12345f"); - floatAsParameter2.push_back(&floatTok2); + std::list floatAsParameter2(1, &floatTok2); TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength("%2.2f", floatAsParameter2)); TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength("%.2f", floatAsParameter)); TODO_ASSERT_EQUALS(7, 5, CheckBufferOverrun::countSprintfLength("%4.2f", floatAsParameter)); - std::list multipleParams; - multipleParams.push_back(&strTok); - multipleParams.push_back(0); - multipleParams.push_back(&numTok); + std::list multipleParams = { &strTok, nullptr, &numTok }; ASSERT_EQUALS(15, CheckBufferOverrun::countSprintfLength("str%s%d%d", multipleParams)); ASSERT_EQUALS(26, CheckBufferOverrun::countSprintfLength("str%-6s%08ld%08ld", multipleParams)); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index cca1c6124..9723ac993 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -114,8 +114,7 @@ private: settings0.inconclusive = inconclusive; // Raw tokens.. - std::vector files; - files.push_back(filename); + std::vector files(1, filename); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index c27de54ac..877e88650 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -120,9 +120,7 @@ private: } void ErrorMessageConstructLocations() const { - std::list locs; - locs.push_back(fooCpp5); - locs.push_back(barCpp8); + std::list locs = { fooCpp5, barCpp8 }; ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false); ASSERT_EQUALS(2, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); @@ -142,9 +140,7 @@ private: } void ErrorMessageVerboseLocations() const { - std::list locs; - locs.push_back(fooCpp5); - locs.push_back(barCpp8); + std::list locs = { fooCpp5, barCpp8 }; ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(2, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); @@ -175,9 +171,7 @@ private: void CustomFormatLocations() const { // Check that first location from location stack is used in template - std::list locs; - locs.push_back(fooCpp5); - locs.push_back(barCpp8); + std::list locs = { fooCpp5, barCpp8 }; ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(2, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); @@ -202,9 +196,7 @@ private: } void ToXmlV2Locations() const { - std::list locs; - locs.push_back(fooCpp5); - locs.push_back(barCpp8); + std::list locs = { fooCpp5, barCpp8 }; ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); std::string header("\n\n"); header += " in; - in.push_back("../include"); + std::list in(1, "../include"); std::map variables; fs.setIncludePaths("abc/def/", in, variables); ASSERT_EQUALS(1U, fs.includePaths.size()); @@ -74,8 +73,7 @@ private: void setIncludePaths2() const { ImportProject::FileSettings fs; - std::list in; - in.push_back("$(SolutionDir)other"); + std::list in(1, "$(SolutionDir)other"); std::map variables; variables["SolutionDir"] = "c:/abc/"; fs.setIncludePaths("/home/fred", in, variables); @@ -85,8 +83,7 @@ private: void setIncludePaths3() const { // macro names are case insensitive ImportProject::FileSettings fs; - std::list in; - in.push_back("$(SOLUTIONDIR)other"); + std::list in(1, "$(SOLUTIONDIR)other"); std::map variables; variables["SolutionDir"] = "c:/abc/"; fs.setIncludePaths("/home/fred", in, variables); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 430f222ca..ab4c079a5 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -39,8 +39,7 @@ private: // Raw tokens.. - std::vector files; - files.push_back("test.cpp"); + std::vector files(1, "test.cpp"); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 9a9ece2b0..fc71e444c 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -404,8 +404,7 @@ private: // getcode.. CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings2, nullptr); - std::list callstack; - callstack.push_back(0); + std::list callstack(1, nullptr); CheckMemoryLeak::AllocType allocType, deallocType; allocType = deallocType = CheckMemoryLeak::No; Token *tokens = checkMemoryLeak.getcode(start, callstack, varId, allocType, deallocType, classfunc, 1); @@ -6041,8 +6040,7 @@ private: errout.str(""); std::istringstream istr(code); - std::vector files; - files.push_back("test.cpp"); + std::vector files(1, "test.cpp"); const simplecpp::TokenList tokens1(istr, files, files[0]); // Preprocess... diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 7424ffd8e..955229f5a 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -136,8 +136,7 @@ private: settings.inconclusive = false; // Raw tokens.. - std::vector files; - files.push_back("test.cpp"); + std::vector files(1, "test.cpp"); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); diff --git a/test/testother.cpp b/test/testother.cpp index c382642b1..bcbf33977 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -254,8 +254,7 @@ private: settings->experimental = false; // Raw tokens.. - std::vector files; - files.push_back(filename); + std::vector files(1, filename); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); diff --git a/test/testpath.cpp b/test/testpath.cpp index fdbd1ee8b..89706fd5d 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -91,11 +91,12 @@ private: } void getRelative() const { - std::vector basePaths; - basePaths.push_back(""); // Don't crash with empty paths - basePaths.push_back("C:/foo"); - basePaths.push_back("C:/bar/"); - basePaths.push_back("C:/test.cpp"); + std::vector basePaths = { + "", // Don't crash with empty paths + "C:/foo", + "C:/bar/", + "C:/test.cpp" + }; ASSERT_EQUALS("x.c", Path::getRelativePath("C:/foo/x.c", basePaths)); ASSERT_EQUALS("y.c", Path::getRelativePath("C:/bar/y.c", basePaths)); diff --git a/test/testpathmatch.cpp b/test/testpathmatch.cpp index 402cb821e..9c79ce0d2 100644 --- a/test/testpathmatch.cpp +++ b/test/testpathmatch.cpp @@ -134,33 +134,25 @@ private: } void twomasklongerpath1() const { - std::vector masks; - masks.push_back("src/"); - masks.push_back("module/"); + std::vector masks = { "src/", "module/" }; PathMatch match(masks); ASSERT(!match.match("project/")); } void twomasklongerpath2() const { - std::vector masks; - masks.push_back("src/"); - masks.push_back("module/"); + std::vector masks = { "src/", "module/" }; PathMatch match(masks); ASSERT(match.match("project/src/")); } void twomasklongerpath3() const { - std::vector masks; - masks.push_back("src/"); - masks.push_back("module/"); + std::vector masks = { "src/", "module/" }; PathMatch match(masks); ASSERT(match.match("project/module/")); } void twomasklongerpath4() const { - std::vector masks; - masks.push_back("src/"); - masks.push_back("module/"); + std::vector masks = { "src/", "module/" }; PathMatch match(masks); ASSERT(match.match("project/src/module/")); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 95a44c2ad..c3020fb05 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -2210,13 +2210,12 @@ private: void validateCfg() { Preprocessor preprocessor(settings0, this); - std::list macroUsageList; std::vector files(1, "test.c"); simplecpp::MacroUsage macroUsage(files); macroUsage.useLocation.fileIndex = 0; macroUsage.useLocation.line = 1; macroUsage.macroName = "X"; - macroUsageList.push_back(macroUsage); + std::list macroUsageList(1, macroUsage); ASSERT_EQUALS(true, preprocessor.validateCfg("", macroUsageList)); ASSERT_EQUALS(false, preprocessor.validateCfg("X",macroUsageList)); diff --git a/test/testsamples.cpp b/test/testsamples.cpp index 97d5d6f3c..a2a9fff8b 100644 --- a/test/testsamples.cpp +++ b/test/testsamples.cpp @@ -105,14 +105,15 @@ private: void runConsoleCodePageTranslationOnWindows() const { REDIRECT; - std::vector msgs; - msgs.push_back("ASCII"); // first entry should be using only ASCII - msgs.push_back("kääk"); - msgs.push_back("Português"); -// msgs.push_back("日本語"); -// msgs.push_back("한국어"); -// msgs.push_back("Русский"); -// msgs.push_back("中文"); + std::vector msgs = { + "ASCII", // first entry should be using only ASCII + "kääk", + "Português" + // "日本語", + // "한국어", + // "Русский", + // "中文", + }; Settings set1; Settings setXML; diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 24ca52748..9d86d5096 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -70,8 +70,7 @@ private: errout.str(""); // Raw tokens.. - std::vector files; - files.push_back("test.cpp"); + std::vector files(1, "test.cpp"); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index d45b33877..4769c6704 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -43,7 +43,12 @@ private: std::vector assignmentOps; void run() { - initOps(); + arithmeticalOps = { "+", "-", "*", "/", "%", "<<", ">>" }; + logicalOps = { "&&", "||", "!" }; + comparisonOps = { "==", "!=", "<", "<=", ">", ">=" }; + bitOps = { "&", "|", "^", "~" }; + extendedOps = { ",", "[", "]", "(", ")", "?", ":" }; + assignmentOps = { "=", "+=", "-=", "*=", "/=", "%=", "&=", "^=", "|=", "<<=", ">>=" }; TEST_CASE(nextprevious); TEST_CASE(multiCompare); @@ -546,50 +551,6 @@ private: dest.insert(dest.end(), src.begin(), src.end()); } - void initOps() { - arithmeticalOps.push_back("+"); - arithmeticalOps.push_back("-"); - arithmeticalOps.push_back("*"); - arithmeticalOps.push_back("/"); - arithmeticalOps.push_back("%"); - arithmeticalOps.push_back("<<"); - arithmeticalOps.push_back(">>"); - - logicalOps.push_back("&&"); - logicalOps.push_back("||"); - logicalOps.push_back("!"); - comparisonOps.push_back("=="); - comparisonOps.push_back("!="); - comparisonOps.push_back("<"); - comparisonOps.push_back("<="); - comparisonOps.push_back(">"); - comparisonOps.push_back(">="); - bitOps.push_back("&"); - bitOps.push_back("|"); - bitOps.push_back("^"); - bitOps.push_back("~"); - - extendedOps.push_back(","); - extendedOps.push_back("["); - extendedOps.push_back("]"); - extendedOps.push_back("("); - extendedOps.push_back(")"); - extendedOps.push_back("?"); - extendedOps.push_back(":"); - - assignmentOps.push_back("="); - assignmentOps.push_back("+="); - assignmentOps.push_back("-="); - assignmentOps.push_back("*="); - assignmentOps.push_back("/="); - assignmentOps.push_back("%="); - assignmentOps.push_back("&="); - assignmentOps.push_back("^="); - assignmentOps.push_back("|="); - assignmentOps.push_back("<<="); - assignmentOps.push_back(">>="); - } - void matchOp() { std::vector test_ops; append_vector(test_ops, arithmeticalOps); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 0a9b96d2c..cfeeefdb3 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -90,8 +90,7 @@ private: settings.platform(platform); // Raw tokens.. - std::vector files; - files.push_back("test.cpp"); + std::vector files(1, "test.cpp"); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 2581af9a1..d9f0b7ccd 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -229,8 +229,7 @@ private: settings.debugwarnings = true; errout.str(""); - std::vector files; - files.push_back("test.cpp"); + std::vector files(1, "test.cpp"); std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]);