From 9579b4509d1a99c56ccbbb9dd4892c3fb6368e5a Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 15 Jun 2023 18:36:21 +0200 Subject: [PATCH 1/4] Partial fix for #11770 cppcheckError with unknown macro --- lib/tokenize.cpp | 2 ++ test/testtokenize.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d961a9f6e..cf5303a2c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8106,6 +8106,8 @@ void Tokenizer::reportUnknownMacros() const else unknownMacroError(tok); } + } else if (isCPP() && Token::Match(tok, "public|private|protected %name% :")) { + unknownMacroError(tok->next()); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index af455a0cf..6dcf245be 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6936,6 +6936,14 @@ private: ASSERT_THROW_EQUALS(tokenizeAndStringify("int f() { MACRO(x) return 0; }"), InternalError, "There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it."); + + ASSERT_THROW_EQUALS(tokenizeAndStringify("class C : public QObject {\n" // #11770 + " struct S { static void g() {} };\n" + "private Q_SLOTS:\n" + " void f() { S::g(); }\n" + "};\n"), + InternalError, + "There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it."); } From 19d4ab7d31ed3f26f75105a4e4ae7fa2d70a483f Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 15 Jun 2023 18:52:52 +0200 Subject: [PATCH 2/4] Fix test --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 1f5cb95a8..c6b84e37b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7051,7 +7051,7 @@ private: valueOfTok(code, "c"); code = "class T {\n" - "private slots:\n" + "private:\n" " void f() { D& r = dynamic_cast(*m); }\n" " void g() { m.reset(new D); }\n" "private:\n" From 39d60ca63e6a2ecd8f611344c00c88090975b170 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 15 Jun 2023 18:53:42 +0200 Subject: [PATCH 3/4] Add test --- test/testtokenize.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6dcf245be..2d00e507f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6944,6 +6944,13 @@ private: "};\n"), InternalError, "There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it."); + ASSERT_THROW_EQUALS(tokenizeAndStringify("class C : public QObject {\n" + " struct S { static void g() {} };\n" + "private slots:\n" + " void f() { S::g(); }\n" + "};\n"), + InternalError, + "There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it."); } From c02a9f403a2b89f1b4f168c64c700b0fee0af125 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 15 Jun 2023 19:22:19 +0200 Subject: [PATCH 4/4] Fix tests --- test/teststl.cpp | 2 +- test/testsymboldatabase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index cc8ba3168..c7e28d283 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -5513,7 +5513,7 @@ private: " QString s;\n" "public:\n" " C(QString);\n" - "private slots:\n" + "private:\n" " void f() {\n" " QVERIFY(QDir(s).exists());\n" " }\n" diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 6c664e169..159c4a7e9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -2859,7 +2859,7 @@ private: void symboldatabase2() { check("class foo {\n" - "public slots :\n" + "public:\n" "foo() { }\n" "};"); ASSERT_EQUALS("", errout.str());