Bug 366693 - Classes with Q_OBJECT macro are not parsed correctly
Summary: Classes with Q_OBJECT macro are not parsed correctly
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (old) (other bugs)
Version First Reported In: 4.7.3
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-12 08:07 UTC by Róbert Čerňanský
Modified: 2016-08-20 14:46 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 4.7.4
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Róbert Čerňanský 2016-08-12 08:07:22 UTC
If a C++ class is defined with Q_OBJECT macro then editor show a syntax error:

class Foo: public QObject {
    Q_OBJECT
_p_ublic:  // <-- red underscore is shown under the "p" letter
...
}

As shown above the error is indicated at the 'public' keyword.  The tooltip says:

Problem in Parser:
Unexpected token 'public'

As the result the class members are not recognized (autocompletion does not work).  When Q_OBJECT macro is removed from the source the syntax error disappears.

The Q_OBJECT macro itself is recognized correctly.  The tooltip shows that it is defined in /usr/include/qt5/QtCore/qobjectdefs.h :187 and following preprocessed body:

------------------------------------------
public:  template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject& _q_argument) const  { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }   _Pragma("GCC diagnostic push")      static const QMetaObject staticMetaObject;  virtual const QMetaObject* metaObject() const;  virtual void* qt_metacast(const char*);  virtual int qt_metacall(QMetaObject::Call, int, void**);  static inline QString tr(const char* s, const char* c = nullptr , int n = -1)  { return staticMetaObject.tr(s, c, n); }   static inline QString trUtf8(const char* s, const char* c = nullptr , int n = -1)  { return staticMetaObject.tr(s, c, n); }   private:    __attribute__((visibility("hidden")))   static void qt_static_metacall(QObject*, QMetaObject::Call, int, void**);  _Pragma("GCC diagnostic pop")    struct QPrivateSignal {};
------------------------------------------

With Qt4 it is working correctly.  It was also working correctly with Qt 5.5.  The problem appeared after upgrade to Qt 5.6.1.

I have kdevplatform 1.7.3.  Using CMake build system with GCC in the project.

Reproducible: Always
Comment 1 TheComet 2016-08-17 19:08:29 UTC
I can confirm this. I've had the exact same problem. Someone in the IRC channel (ogoffart) said that adding "#define _Pragma(...)" before including any Qt headers fixes the problem, and indeed it does:

#define _Pragma(...)
#include <QWidget>

class Thing : public QWidget {
    Q_OBJECT
public:  // there is no longer a parser error here
    Thing(QWidget* parent = 0);
};
Comment 2 Milian Wolff 2016-08-17 20:12:42 UTC
Git commit 8769c228a55303c2b6a19f10e05ebc01067108bf by Milian Wolff.
Committed on 17/08/2016 at 20:12.
Pushed by mwolff into branch '4.7'.

Ignore C99 _Pragma macros

Fixes parsing of Q_OBJECT among other things.

M  +8    -0    languages/cpp/setuphelpers.cpp

http://commits.kde.org/kdevelop/8769c228a55303c2b6a19f10e05ebc01067108bf