diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 89dd7adc5..2146c4bf4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8745,16 +8745,17 @@ void Tokenizer::simplifyQtSignalsSlots() { tok2->deleteNext(); } - else if (Token::Match(tok2->next(), "public|protected|private slots :")) + else if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) { tok2 = tok2->next(); tok2->str(tok2->str() + ":"); tok2->deleteNext(); tok2->deleteNext(); } - else if (Token::simpleMatch(tok2->next(), "signals :")) + else if (Token::Match(tok2->next(), "signals|Q_SIGNALS :")) { - tok2->deleteNext(); + tok2 = tok2->next(); + tok2->str("protected:"); tok2->deleteNext(); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a080894ed..7aff76dde 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4774,33 +4774,63 @@ private: void Qt() { - const char code[] = "class Counter : public QObject " - "{ " - " Q_OBJECT " - "public: " - " Counter() { m_value = 0; } " - " int value() const { return m_value; } " - "public slots: " - " void setValue(int value); " - "signals: " - " void valueChanged(int newValue); " - "private: " - " int m_value; " - "};"; + const char code1[] = "class Counter : public QObject " + "{ " + " Q_OBJECT " + "public: " + " Counter() { m_value = 0; } " + " int value() const { return m_value; } " + "public slots: " + " void setValue(int value); " + "signals: " + " void valueChanged(int newValue); " + "private: " + " int m_value; " + "};"; - const char result [] = "class Counter : public QObject " - "{ " - "public: " - "Counter ( ) { m_value = 0 ; } " - "int value ( ) const { return m_value ; } " - "public: " - "void setValue ( int value ) ; " - "void valueChanged ( int newValue ) ; " - "private: " - "int m_value ; " - "} ;"; + const char result1 [] = "class Counter : public QObject " + "{ " + "public: " + "Counter ( ) { m_value = 0 ; } " + "int value ( ) const { return m_value ; } " + "public: " + "void setValue ( int value ) ; " + "protected: " + "void valueChanged ( int newValue ) ; " + "private: " + "int m_value ; " + "} ;"; - ASSERT_EQUALS(result, tokenizeAndStringify(code,false)); + ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false)); + + const char code2[] = "class Counter : public QObject " + "{ " + " Q_OBJECT " + "public: " + " Counter() { m_value = 0; } " + " int value() const { return m_value; } " + "public Q_SLOTS: " + " void setValue(int value); " + "Q_SIGNALS: " + " void valueChanged(int newValue); " + "private: " + " int m_value; " + "};"; + + const char result2 [] = "class Counter : public QObject " + "{ " + "public: " + "Counter ( ) { m_value = 0 ; } " + "int value ( ) const { return m_value ; } " + "public: " + "void setValue ( int value ) ; " + "protected: " + "void valueChanged ( int newValue ) ; " + "private: " + "int m_value ; " + "} ;"; + + ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false)); } void sql()