From 9579b4509d1a99c56ccbbb9dd4892c3fb6368e5a Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 15 Jun 2023 18:36:21 +0200 Subject: [PATCH] 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."); }