diff --git a/gui/cppchecklibrarydata.cpp b/gui/cppchecklibrarydata.cpp index b21ce8ee6..d44c79745 100644 --- a/gui/cppchecklibrarydata.cpp +++ b/gui/cppchecklibrarydata.cpp @@ -329,20 +329,17 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader) QXmlStreamReader::TokenType type; if (xmlReader.attributes().hasAttribute("ext")) { markup.ext = xmlReader.attributes().value("ext").toString(); - } - else { + } else { mandatoryAttibuteMissing(xmlReader, "ext"); } if (xmlReader.attributes().hasAttribute("aftercode")) { markup.afterCode = (xmlReader.attributes().value("aftercode") == "true") ? true : false; - } - else { + } else { mandatoryAttibuteMissing(xmlReader, "aftercode"); } if (xmlReader.attributes().hasAttribute("reporterrors")) { markup.reportErrors = (xmlReader.attributes().value("reporterrors") == "true") ? true : false; - } - else { + } else { mandatoryAttibuteMissing(xmlReader, "reporterrors"); } @@ -358,8 +355,7 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader) continue; if (xmlReader.name().toString() == "keyword") { markup.keywords.append(xmlReader.attributes().value("name").toString()); - } - else { + } else { unhandledElement(xmlReader); } } @@ -372,13 +368,11 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader) continue; if (xmlReader.name().toString() == "block") { codeBlock.blocks.append(xmlReader.attributes().value("name").toString()); - } - else if (xmlReader.name().toString() == "structure") { + } else if (xmlReader.name().toString() == "structure") { codeBlock.offset = xmlReader.attributes().value("offset").toInt(); codeBlock.start = xmlReader.attributes().value("start").toString(); codeBlock.end = xmlReader.attributes().value("end").toString(); - } - else { + } else { unhandledElement(xmlReader); } } @@ -392,14 +386,11 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader) continue; if (xmlReader.name().toString() == "exporter") { exporter.prefix = xmlReader.attributes().value("prefix").toString(); - } - else if (xmlReader.name().toString() == "prefix") { + } else if (xmlReader.name().toString() == "prefix") { exporter.prefixList.append(xmlReader.readElementText()); - } - else if (xmlReader.name().toString() == "suffix") { + } else if (xmlReader.name().toString() == "suffix") { exporter.suffixList.append(xmlReader.readElementText()); - } - else { + } else { unhandledElement(xmlReader); } } @@ -411,8 +402,7 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader) continue; if (xmlReader.name().toString() == "importer") { markup.importer.append(xmlReader.readElementText()); - } - else { + } else { unhandledElement(xmlReader); } } @@ -778,7 +768,7 @@ static void writeMarkup(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData:: } xmlWriter.writeEndElement(); } - if (!mup.codeBlocks.isEmpty()) { + if (!mup.codeBlocks.isEmpty()) { foreach (const CppcheckLibraryData::Markup::CodeBlocks codeblock, mup.codeBlocks) { xmlWriter.writeStartElement("codeblocks"); foreach (const QString &block, codeblock.blocks) { diff --git a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp index 59c1403f0..713b90f2a 100644 --- a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp +++ b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp @@ -481,7 +481,7 @@ void TestCppcheckLibraryData::markupValid() QCOMPARE(libraryData.markups[0].afterCode, true); QCOMPARE(libraryData.markups[0].keywords.size(), 4); - QCOMPARE(libraryData.markups[0].keywords, QStringList( {"if", "while", "typeof", "for"} )); + QCOMPARE(libraryData.markups[0].keywords, QStringList({"if", "while", "typeof", "for"})); QCOMPARE(libraryData.markups[0].importer.size(), 1); QCOMPARE(libraryData.markups[0].importer, QStringList("connect")); @@ -491,11 +491,11 @@ void TestCppcheckLibraryData::markupValid() QCOMPARE(libraryData.markups[0].exporter[0].suffixList.size(), 1); QCOMPARE(libraryData.markups[0].exporter[0].suffixList, QStringList("READ")); QCOMPARE(libraryData.markups[0].exporter[0].prefixList.size(), 3); - QCOMPARE(libraryData.markups[0].exporter[0].prefixList, QStringList( {"READ", "WRITE", "NOTIFY"} )); + QCOMPARE(libraryData.markups[0].exporter[0].prefixList, QStringList({"READ", "WRITE", "NOTIFY"})); QCOMPARE(libraryData.markups[0].codeBlocks.size(), 2); QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks.size(), 5); - QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks, QStringList( {"onClicked", "onFinished", "onTriggered", "onPressed", "onTouch"} )); + QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks, QStringList({"onClicked", "onFinished", "onTriggered", "onPressed", "onTouch"})); QCOMPARE(libraryData.markups[0].codeBlocks[0].offset, 3); QCOMPARE(libraryData.markups[0].codeBlocks[0].start, "{"); QCOMPARE(libraryData.markups[0].codeBlocks[0].end, "}"); diff --git a/lib/astutils.cpp b/lib/astutils.cpp index dd6fed54e..f1a737451 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -755,13 +755,12 @@ static void followVariableExpressionError(const Token *tok1, const Token *tok2, std::vector followAllReferences(const Token* tok, bool inconclusive, ErrorPath errors, int depth) { struct ReferenceTokenLess { - bool operator()(const ReferenceToken& x, const ReferenceToken& y) const - { + bool operator()(const ReferenceToken& x, const ReferenceToken& y) const { return x.token < y.token; } }; if (!tok) - return std::vector{}; + return std::vector {}; if (depth < 0) return {{tok, std::move(errors)}}; const Variable *var = tok->variable(); @@ -811,7 +810,7 @@ std::vector followAllReferences(const Token* tok, bool inconclus if (returnTok == tok) continue; std::vector argvarRt = followAllReferences(returnTok, inconclusive, errors, depth - 1); - for(const ReferenceToken& rt:followAllReferences(returnTok, inconclusive, errors, depth - 1)) { + for (const ReferenceToken& rt:followAllReferences(returnTok, inconclusive, errors, depth - 1)) { const Variable* argvar = rt.token->variable(); if (!argvar) return {{tok, std::move(errors)}}; @@ -830,7 +829,7 @@ std::vector followAllReferences(const Token* tok, bool inconclus result.insert(refs.begin(), refs.end()); if (!inconclusive && result.size() > 1) return {{tok, std::move(errors)}}; - } + } } } if (!result.empty()) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a1352f6cc..385befab1 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2845,7 +2845,9 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti // the full definition must be compared bool fullDefinition = std::all_of(classScope->functionList.begin(), classScope->functionList.end(), - [](const Function& f) { return f.hasBody(); }); + [](const Function& f) { + return f.hasBody(); + }); if (!fullDefinition) continue; diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index d5ec2dced..440dd2233 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -584,7 +584,6 @@ void execute(const Token *expr, *result = 0; else *error = true; - } - else + } else *error = true; } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index e004a918d..bb747eab5 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2001,8 +2001,7 @@ struct ValueFlowAnalyzer : Analyzer { return isModified(tok); } - Action analyzeToken(const Token* ref, const Token* tok, Direction d, bool inconclusiveRef) const - { + Action analyzeToken(const Token* ref, const Token* tok, Direction d, bool inconclusiveRef) const { if (!ref) return Action::None; // If its an inconclusiveRef then ref != tok @@ -2054,7 +2053,7 @@ struct ValueFlowAnalyzer : Analyzer { // Follow references std::vector refs = followAllReferences(tok); const bool inconclusiveRefs = refs.size() != 1; - for(const ReferenceToken& ref:refs) { + for (const ReferenceToken& ref:refs) { Action a = analyzeToken(ref.token, tok, d, inconclusiveRefs); if (a != Action::None) return a; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 456807edc..7c28e286f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5038,18 +5038,18 @@ private: "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0)); - code = "bool f(std::string s) {\n" - " if (!s.empty()) {\n" - " bool x = s == \"0\";\n" - " return x;\n" - " }\n" - " return false;\n" - "}\n"; - ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 0)); - ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1)); - ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0)); - - code = "bool f() {\n" + code = "bool f(std::string s) {\n" + " if (!s.empty()) {\n" + " bool x = s == \"0\";\n" + " return x;\n" + " }\n" + " return false;\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 0)); + ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1)); + ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0)); + + code = "bool f() {\n" " std::list x1;\n" " std::list x2;\n" " for (int i = 0; i < 10; ++i) {\n" @@ -5060,7 +5060,7 @@ private: "}\n"; ASSERT_EQUALS("", isInconclusiveContainerSizeValue(tokenValues(code, "x1 . empty", ValueFlow::Value::ValueType::CONTAINER_SIZE), 0)); ASSERT_EQUALS("", isInconclusiveContainerSizeValue(tokenValues(code, "x2 . empty", ValueFlow::Value::ValueType::CONTAINER_SIZE), 0)); - + code = "std::vector g();\n" "int f(bool b) {\n" " std::set a;\n"