From 62ac40fc5e3c296809cf6ad28e2865e1e7a50eed Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 20 Aug 2016 22:43:27 +0200 Subject: [PATCH] Fixed #7706 ((debug) Executable scope 'foo' with unknown function.) --- lib/tokenize.cpp | 6 +++--- test/testsymboldatabase.cpp | 14 ++++++++++++++ test/testtokenize.cpp | 10 ++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) 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() {