From 83d1a6871e7ce7b8c2ace059423d5a4f8670e015 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 10 Jun 2025 22:02:47 +0200 Subject: [PATCH 01/16] Fix #10431 FP one-definition-rule if struct in mutually exclusive #ifdef branches --- lib/check.h | 2 +- lib/checkbufferoverrun.cpp | 2 +- lib/checkbufferoverrun.h | 2 +- lib/checkclass.cpp | 6 +++++- lib/checkclass.h | 2 +- lib/checknullpointer.cpp | 2 +- lib/checknullpointer.h | 2 +- lib/checkuninitvar.cpp | 2 +- lib/checkuninitvar.h | 2 +- lib/cppcheck.cpp | 8 ++++---- lib/cppcheck.h | 2 +- test/cli/whole-program/odr3.cpp | 5 +++++ 12 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 test/cli/whole-program/odr3.cpp diff --git a/lib/check.h b/lib/check.h index 6729443f783..a3d3191b68c 100644 --- a/lib/check.h +++ b/lib/check.h @@ -110,7 +110,7 @@ class CPPCHECKLIB Check { std::string file0; }; - virtual FileInfo * getFileInfo(const Tokenizer& /*tokenizer*/, const Settings& /*settings*/) const { + virtual FileInfo * getFileInfo(const Tokenizer& /*tokenizer*/, const Settings& /*settings*/, const std::string& /*currentConfig*/) const { return nullptr; } diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index e79f8d05c6f..0c19bceb137 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -947,7 +947,7 @@ bool CheckBufferOverrun::isCtuUnsafePointerArith(const Settings &settings, const } /** @brief Parse current TU and extract file info */ -Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const +Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& /*currentConfig*/) const { const std::list &unsafeArrayIndex = CTU::getUnsafeUsage(tokenizer, settings, isCtuUnsafeArrayIndex); const std::list &unsafePointerArith = CTU::getUnsafeUsage(tokenizer, settings, isCtuUnsafePointerArith); diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index d945fd7b1e5..9c6e1f0386d 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -72,7 +72,7 @@ class CPPCHECKLIB CheckBufferOverrun : public Check { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; /** @brief Parse current TU and extract file info */ - Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const override; + Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& /*currentConfig*/) const override; /** @brief Analyse all file infos for all TU */ bool analyseWholeProgram(const CTU::FileInfo &ctu, const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 6fd15dafc72..e9d04ffe8f0 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3563,6 +3563,7 @@ namespace struct NameLoc { std::string className; std::string fileName; + std::string configuration; int lineNumber; int column; std::size_t hash; @@ -3592,7 +3593,7 @@ namespace }; } -Check::FileInfo *CheckClass::getFileInfo(const Tokenizer &tokenizer, const Settings& /*settings*/) const +Check::FileInfo *CheckClass::getFileInfo(const Tokenizer &tokenizer, const Settings& /*settings*/, const std::string& currentConfig) const { if (!tokenizer.isCPP()) return nullptr; @@ -3649,6 +3650,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer &tokenizer, const Setti } } nameLoc.hash = std::hash {}(def); + nameLoc.configuration = currentConfig; classDefinitions.push_back(std::move(nameLoc)); } @@ -3716,6 +3718,8 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo &ctu, const std::listsecond.hash == nameLoc.hash) + continue; + if (it->second.configuration != nameLoc.configuration) continue; // Same location, sometimes the hash is different wrongly (possibly because of different token simplifications). if (it->second.isSameLocation(nameLoc)) diff --git a/lib/checkclass.h b/lib/checkclass.h index f59594b20ca..130f6ffd781 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -138,7 +138,7 @@ class CPPCHECKLIB CheckClass : public Check { void checkUnsafeClassRefMember(); /** @brief Parse current TU and extract file info */ - Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const override; + Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& currentConfig) const override; Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override; diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 3ad0a381d06..5be1622764d 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -620,7 +620,7 @@ namespace }; } -Check::FileInfo *CheckNullPointer::getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const +Check::FileInfo *CheckNullPointer::getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& /*currentConfig*/) const { const std::list &unsafeUsage = CTU::getUnsafeUsage(tokenizer, settings, isUnsafeUsage); if (unsafeUsage.empty()) diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index fb59771a64e..d28927d19e9 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -93,7 +93,7 @@ class CPPCHECKLIB CheckNullPointer : public Check { void nullPointerError(const Token *tok, const std::string &varname, const ValueFlow::Value* value, bool inconclusive); /** @brief Parse current TU and extract file info */ - Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const override; + Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& /*currentConfig*/) const override; Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override; diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f9fba3b5c08..ddbdfee5496 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1730,7 +1730,7 @@ static bool isVariableUsage(const Settings &settings, const Token *argtok, CTU:: return isVariableUsage(settings, argtok, &value->value); } -Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const +Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& /*currentConfig*/) const { const std::list &unsafeUsage = CTU::getUnsafeUsage(tokenizer, settings, ::isVariableUsage); if (unsafeUsage.empty()) diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index 6c1b4c67b14..b79e9c22be0 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -96,7 +96,7 @@ class CPPCHECKLIB CheckUninitVar : public Check { void valueFlowUninit(); /** @brief Parse current TU and extract file info */ - Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const override; + Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& /*currentConfig*/) const override; Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index baecb950e60..620f0478164 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -727,7 +727,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex) mSettings, &s_timerResults); tokenizer.printDebugOutput(std::cout); - checkNormalTokens(tokenizer, nullptr); // TODO: provide analyzer information + checkNormalTokens(tokenizer, nullptr, ""); // TODO: provide analyzer information // create dumpfile std::ofstream fdump; @@ -1203,7 +1203,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string } // Check normal tokens - checkNormalTokens(tokenizer, analyzerInformation.get()); + checkNormalTokens(tokenizer, analyzerInformation.get(), currentConfig); } catch (const InternalError &e) { ErrorMessage errmsg = ErrorMessage::fromInternalError(e, &tokenizer.list, file.spath()); mErrorLogger.reportErr(errmsg); @@ -1327,7 +1327,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg // CppCheck - A function that checks a normal token list //--------------------------------------------------------------------------- -void CppCheck::checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation* analyzerInformation) +void CppCheck::checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation* analyzerInformation, const std::string& currentConfig) { CheckUnusedFunctions unusedFunctionsChecker; @@ -1392,7 +1392,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation if (!doUnusedFunctionOnly) { // cppcheck-suppress shadowFunction - TODO: fix this for (const Check *check : Check::instances()) { - if (Check::FileInfo * const fi = check->getFileInfo(tokenizer, mSettings)) { + if (Check::FileInfo * const fi = check->getFileInfo(tokenizer, mSettings, currentConfig)) { if (analyzerInformation) analyzerInformation->setFileInfo(check->name(), fi->toString()); if (mSettings.useSingleJob()) diff --git a/lib/cppcheck.h b/lib/cppcheck.h index d7c326704a1..f23a3861d80 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -176,7 +176,7 @@ class CPPCHECKLIB CppCheck { * @param tokenizer tokenizer instance * @param analyzerInformation the analyzer infomation */ - void checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation* analyzerInformation); + void checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation* analyzerInformation, const std::string& currentConfig); /** * Execute addons diff --git a/test/cli/whole-program/odr3.cpp b/test/cli/whole-program/odr3.cpp new file mode 100644 index 00000000000..b61a72acc19 --- /dev/null +++ b/test/cli/whole-program/odr3.cpp @@ -0,0 +1,5 @@ +#ifdef X +struct S { int i; }; +#else +struct S {}; +#endif \ No newline at end of file From c062f2799576bf6fa5eacab2e20af5c683f13dd0 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 10 Jun 2025 22:06:16 +0200 Subject: [PATCH 02/16] Comment --- test/cli/whole-program/odr3.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cli/whole-program/odr3.cpp b/test/cli/whole-program/odr3.cpp index b61a72acc19..c36239d6a3d 100644 --- a/test/cli/whole-program/odr3.cpp +++ b/test/cli/whole-program/odr3.cpp @@ -1,3 +1,4 @@ +// #10431 #ifdef X struct S { int i; }; #else From 3270d8599e38beda2435cc4390a6ce07ca09eea9 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 10 Jun 2025 22:08:33 +0200 Subject: [PATCH 03/16] Suppress --- test/cli/whole-program/odr3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/whole-program/odr3.cpp b/test/cli/whole-program/odr3.cpp index c36239d6a3d..0fa6b9558ff 100644 --- a/test/cli/whole-program/odr3.cpp +++ b/test/cli/whole-program/odr3.cpp @@ -1,6 +1,6 @@ // #10431 #ifdef X -struct S { int i; }; +struct S { int i; }; // cppcheck-suppress unusedStructMember #else struct S {}; #endif \ No newline at end of file From 02187600d805920bf33666c74bc315cec7fab582 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 10 Jun 2025 22:24:18 +0200 Subject: [PATCH 04/16] Fix --- test/testbufferoverrun.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index c0600bcdf53..b13746a5b4b 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -5245,7 +5245,7 @@ class TestBufferOverrun : public TestFixture { // Check code.. std::list fileInfo; Check& c = getCheck(); - fileInfo.push_back(c.getFileInfo(tokenizer, settings0)); + fileInfo.push_back(c.getFileInfo(tokenizer, settings0, "")); c.analyseWholeProgram(*ctu, fileInfo, settings0, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); From 63651709d20def6a3fe5ecb08286d9a002f611f0 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 10 Jun 2025 22:36:36 +0200 Subject: [PATCH 05/16] Fix --- test/testclass.cpp | 4 ++-- test/testnullpointer.cpp | 2 +- test/testuninitvar.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 8eeb7eb7696..aeb015754e6 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -9084,7 +9084,7 @@ class TestClass : public TestFixture { const std::string filename = std::to_string(fileInfo.size()) + ".cpp"; SimpleTokenizer tokenizer{settingsDefault, *this, filename}; ASSERT(tokenizer.tokenize(c)); - fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault)); + fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, "")); } // Check code.. @@ -9130,7 +9130,7 @@ class TestClass : public TestFixture { // Check.. const Check& c = getCheck(); - Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1); + Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, ""); delete fileInfo; } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 667f25aa8cb..ba6ecfac938 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4587,7 +4587,7 @@ class TestNullPointer : public TestFixture { // Check code.. std::list fileInfo; Check& c = getCheck(); - fileInfo.push_back(c.getFileInfo(tokenizer, settings)); + fileInfo.push_back(c.getFileInfo(tokenizer, settings, "")); c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 1eb59cbedad..dfdc048b4f9 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -7923,7 +7923,7 @@ class TestUninitVar : public TestFixture { // Check code.. std::list fileInfo; Check& c = getCheck(); - fileInfo.push_back(c.getFileInfo(tokenizer, settings)); + fileInfo.push_back(c.getFileInfo(tokenizer, settings, "")); c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); From cc1e803c0ef01281c7f4ad09d24ea374d90d4b06 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 10 Jun 2025 22:40:29 +0200 Subject: [PATCH 06/16] Format --- lib/checkclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index e9d04ffe8f0..d7c124faaae 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3718,7 +3718,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo &ctu, const std::listsecond.hash == nameLoc.hash) - continue; + continue; if (it->second.configuration != nameLoc.configuration) continue; // Same location, sometimes the hash is different wrongly (possibly because of different token simplifications). From fe0391ddf296df221383cda857ed01f805a8db72 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 18:30:03 +0200 Subject: [PATCH 07/16] Fix test --- test/cli/whole-program/odr3.cpp | 2 +- test/cli/whole-program_test.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/cli/whole-program/odr3.cpp b/test/cli/whole-program/odr3.cpp index 0fa6b9558ff..8ce2fc8c072 100644 --- a/test/cli/whole-program/odr3.cpp +++ b/test/cli/whole-program/odr3.cpp @@ -3,4 +3,4 @@ struct S { int i; }; // cppcheck-suppress unusedStructMember #else struct S {}; -#endif \ No newline at end of file +#endif diff --git a/test/cli/whole-program_test.py b/test/cli/whole-program_test.py index 01b79a4060c..bc3e14c1ae2 100644 --- a/test/cli/whole-program_test.py +++ b/test/cli/whole-program_test.py @@ -254,7 +254,8 @@ def __test_checkclass(extra_args): '--enable=information,style', '--error-exitcode=1', 'whole-program/odr1.cpp', - 'whole-program/odr2.cpp' + 'whole-program/odr2.cpp', + 'whole-program/odr3.cpp' ] args += extra_args From cee78ce3accfb8cce0c3432ea20231de21cef6ee Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 19:14:41 +0200 Subject: [PATCH 08/16] Fix --- test/cli/whole-program/odr3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/whole-program/odr3.cpp b/test/cli/whole-program/odr3.cpp index 8ce2fc8c072..d7e1015a87c 100644 --- a/test/cli/whole-program/odr3.cpp +++ b/test/cli/whole-program/odr3.cpp @@ -1,6 +1,6 @@ // #10431 #ifdef X -struct S { int i; }; // cppcheck-suppress unusedStructMember +struct S { S(); }; #else struct S {}; #endif From 1719e4e6a1c0daba9dcc1f18fc0c3c7c8fdfbee5 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 19:46:16 +0200 Subject: [PATCH 09/16] Warn if both file and configuration are different --- lib/checkclass.cpp | 2 +- test/cli/whole-program/odr4.cpp | 3 +++ test/cli/whole-program/odr5.cpp | 1 + test/cli/whole-program_test.py | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/cli/whole-program/odr4.cpp create mode 100644 test/cli/whole-program/odr5.cpp diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d7c124faaae..50bc1cb1d40 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3719,7 +3719,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo &ctu, const std::listsecond.hash == nameLoc.hash) continue; - if (it->second.configuration != nameLoc.configuration) + if (it->second.fileName == nameLoc.fileName && it->second.configuration != nameLoc.configuration) continue; // Same location, sometimes the hash is different wrongly (possibly because of different token simplifications). if (it->second.isSameLocation(nameLoc)) diff --git a/test/cli/whole-program/odr4.cpp b/test/cli/whole-program/odr4.cpp new file mode 100644 index 00000000000..c50bdda949f --- /dev/null +++ b/test/cli/whole-program/odr4.cpp @@ -0,0 +1,3 @@ +#ifdef X +struct S {}; +#endif diff --git a/test/cli/whole-program/odr5.cpp b/test/cli/whole-program/odr5.cpp new file mode 100644 index 00000000000..e1bc9ff103e --- /dev/null +++ b/test/cli/whole-program/odr5.cpp @@ -0,0 +1 @@ +struct S {}; diff --git a/test/cli/whole-program_test.py b/test/cli/whole-program_test.py index bc3e14c1ae2..7afadce36d9 100644 --- a/test/cli/whole-program_test.py +++ b/test/cli/whole-program_test.py @@ -337,6 +337,24 @@ def test_checkclass_project_builddir_j(tmpdir): os.mkdir(build_dir) __test_checkclass_project(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir)]) +def test_ctu_odr_config(): + args = [ + '-q', + '--template=simple', + '--enable=information,style', + '--error-exitcode=1', + 'whole-program/odr4.cpp', + 'whole-program/odr5.cpp' + ] + + ret, stdout, stderr = cppcheck(args, cwd=__script_dir) + lines = stderr.splitlines() + assert lines == [ + "whole-program{}odr4.cpp:6:1: error: The one definition rule is violated, different classes/structs have the same name 'S' [ctuOneDefinitionRuleViolation]".format(os.path.sep) + ] + assert stdout == '' + assert ret == 1, stdout + def __test_nullpointer_file0(extra_args): args = [ From 9761e6a41c2c69a9460e1ffc2cb85abfc5a4c3e9 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 20:10:16 +0200 Subject: [PATCH 10/16] Fix --- test/cli/whole-program/odr5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/whole-program/odr5.cpp b/test/cli/whole-program/odr5.cpp index e1bc9ff103e..4b2d03c7360 100644 --- a/test/cli/whole-program/odr5.cpp +++ b/test/cli/whole-program/odr5.cpp @@ -1 +1 @@ -struct S {}; +struct S { S(); }; From 8a3abe466c3891962d9d3ec9a3dafb9f2066e450 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 22:37:17 +0200 Subject: [PATCH 11/16] Fix --- test/cli/whole-program/odr5.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cli/whole-program/odr5.cpp b/test/cli/whole-program/odr5.cpp index 4b2d03c7360..4f96e90d836 100644 --- a/test/cli/whole-program/odr5.cpp +++ b/test/cli/whole-program/odr5.cpp @@ -1 +1,3 @@ -struct S { S(); }; +struct S { + void f() {} +}; From cd4e41da2f9476a3fbf5b8f3349b678b3edfed7d Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 22:43:17 +0200 Subject: [PATCH 12/16] Fix --- test/cli/whole-program_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/whole-program_test.py b/test/cli/whole-program_test.py index 7afadce36d9..10c726feb9b 100644 --- a/test/cli/whole-program_test.py +++ b/test/cli/whole-program_test.py @@ -350,7 +350,7 @@ def test_ctu_odr_config(): ret, stdout, stderr = cppcheck(args, cwd=__script_dir) lines = stderr.splitlines() assert lines == [ - "whole-program{}odr4.cpp:6:1: error: The one definition rule is violated, different classes/structs have the same name 'S' [ctuOneDefinitionRuleViolation]".format(os.path.sep) + "whole-program{}odr4.cpp:2:1: error: The one definition rule is violated, different classes/structs have the same name 'S' [ctuOneDefinitionRuleViolation]".format(os.path.sep) ] assert stdout == '' assert ret == 1, stdout From 04083fbd1e338b260512c3f60ced7ea3316bc553 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 12 Jun 2025 23:29:41 +0200 Subject: [PATCH 13/16] Rename, fix --- test/cli/whole-program/odr3.cpp | 2 +- test/cli/whole-program/{odr4.cpp => odr_cfg1.cpp} | 0 test/cli/whole-program/{odr5.cpp => odr_cfg2.cpp} | 0 test/cli/whole-program_test.py | 6 +++--- 4 files changed, 4 insertions(+), 4 deletions(-) rename test/cli/whole-program/{odr4.cpp => odr_cfg1.cpp} (100%) rename test/cli/whole-program/{odr5.cpp => odr_cfg2.cpp} (100%) diff --git a/test/cli/whole-program/odr3.cpp b/test/cli/whole-program/odr3.cpp index d7e1015a87c..a4c555e5b7e 100644 --- a/test/cli/whole-program/odr3.cpp +++ b/test/cli/whole-program/odr3.cpp @@ -1,6 +1,6 @@ // #10431 #ifdef X -struct S { S(); }; +struct S { S() {} }; #else struct S {}; #endif diff --git a/test/cli/whole-program/odr4.cpp b/test/cli/whole-program/odr_cfg1.cpp similarity index 100% rename from test/cli/whole-program/odr4.cpp rename to test/cli/whole-program/odr_cfg1.cpp diff --git a/test/cli/whole-program/odr5.cpp b/test/cli/whole-program/odr_cfg2.cpp similarity index 100% rename from test/cli/whole-program/odr5.cpp rename to test/cli/whole-program/odr_cfg2.cpp diff --git a/test/cli/whole-program_test.py b/test/cli/whole-program_test.py index 10c726feb9b..56c6c09a125 100644 --- a/test/cli/whole-program_test.py +++ b/test/cli/whole-program_test.py @@ -343,14 +343,14 @@ def test_ctu_odr_config(): '--template=simple', '--enable=information,style', '--error-exitcode=1', - 'whole-program/odr4.cpp', - 'whole-program/odr5.cpp' + 'whole-program/odr_cfg1.cpp', + 'whole-program/odr_cfg2.cpp' ] ret, stdout, stderr = cppcheck(args, cwd=__script_dir) lines = stderr.splitlines() assert lines == [ - "whole-program{}odr4.cpp:2:1: error: The one definition rule is violated, different classes/structs have the same name 'S' [ctuOneDefinitionRuleViolation]".format(os.path.sep) + "whole-program{}odr_cfg1.cpp:2:1: error: The one definition rule is violated, different classes/structs have the same name 'S' [ctuOneDefinitionRuleViolation]".format(os.path.sep) ] assert stdout == '' assert ret == 1, stdout From 657874c4264c7796c938943ff62a387c3dabba71 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 13 Jun 2025 18:48:53 +0200 Subject: [PATCH 14/16] Fix builddir --- lib/checkclass.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 50bc1cb1d40..75867fc1469 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3583,6 +3583,7 @@ namespace for (const NameLoc &nameLoc: classDefinitions) { ret += "Attribute("name"); const char *file = e->Attribute("file"); + const char *configuration = e->Attribute("configuration"); const char *line = e->Attribute("line"); const char *col = e->Attribute("col"); const char *hash = e->Attribute("hash"); - if (name && file && line && col && hash) { + if (name && file && configuration && line && col && hash) { MyFileInfo::NameLoc nameLoc; nameLoc.className = name; nameLoc.fileName = file; + nameLoc.configuration = configuration; nameLoc.lineNumber = strToInt(line); nameLoc.column = strToInt(col); nameLoc.hash = strToInt(hash); From 48f52270a7091cdb3cd61761941abd9e5ad16b4e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 13 Jun 2025 20:17:46 +0200 Subject: [PATCH 15/16] Align --- test/cli/whole-program/odr_cfg2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/whole-program/odr_cfg2.cpp b/test/cli/whole-program/odr_cfg2.cpp index 4f96e90d836..2b439177aad 100644 --- a/test/cli/whole-program/odr_cfg2.cpp +++ b/test/cli/whole-program/odr_cfg2.cpp @@ -1,3 +1,3 @@ struct S { - void f() {} + S() {} }; From a9a095f1d5c80658a0b6417fa3c44cc40f78fa97 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 13 Jun 2025 20:45:53 +0200 Subject: [PATCH 16/16] Only test with -j1 --- test/cli/whole-program_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cli/whole-program_test.py b/test/cli/whole-program_test.py index 56c6c09a125..dfb4e8112d1 100644 --- a/test/cli/whole-program_test.py +++ b/test/cli/whole-program_test.py @@ -340,6 +340,7 @@ def test_checkclass_project_builddir_j(tmpdir): def test_ctu_odr_config(): args = [ '-q', + '-j1', '--template=simple', '--enable=information,style', '--error-exitcode=1',