diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 00a39e76d..636215114 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/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()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index af455a0cf..2d00e507f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6936,6 +6936,21 @@ 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."); + 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."); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 6e36c1896..1645a92cf 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7074,7 +7074,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"