diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 76db9bdff..e72c5d24a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9215,10 +9215,10 @@ void Tokenizer::simplifyQtSignalsSlots() else --indentlevel; } - - if (tok2->strAt(1) == "Q_OBJECT") { + if (tok2->strAt(1) == "Q_OBJECT") tok2->deleteNext(); - } else if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) { + + if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) { tok2 = tok2->next(); tok2->str(tok2->str() + ":"); tok2->deleteNext(2); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index bd4984efe..90d2e31e1 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -279,6 +279,7 @@ private: TEST_CASE(findFunction8); TEST_CASE(findFunction9); TEST_CASE(findFunction10); // #7673 + TEST_CASE(findFunction11); TEST_CASE(noexceptFunction1); TEST_CASE(noexceptFunction2); @@ -3417,6 +3418,19 @@ private: ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 2); } + void findFunction11() { + GET_SYMBOL_DB("class Fred : public QObject {\n" + " Q_OBJECT\n" + "private slots:\n" + " void foo();\n" + "};\n" + "void Fred::foo() { }"); + ASSERT_EQUALS("", errout.str()); + + const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( ) {"); + ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 4); + } + #define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \ ASSERT_EQUALS(true, x != nullptr); \ if (x) ASSERT_EQUALS(true, x->isNoExcept()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0294f5658..45c66b5ab 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5625,6 +5625,16 @@ private: ASSERT_EQUALS(result3, tokenizeAndStringify(code3,false)); ASSERT_EQUALS("", errout.str()); + + const char code4[] = "class MyObject : public QObject {" + " Q_OBJECT " + "public slots:" + "};"; + const char result4[] = "class MyObject : public QObject { " + "public: " + "} ;"; + + ASSERT_EQUALS(result4, tokenizeAndStringify(code4,false)); } void simplifySQL() {