https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100796
Bug ID: 100796
Summary: [11 Regression] GCC does not honor #pragma diagnostic
ignored when using the integrated preprocessor
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dangelog at gmail dot com
Target Milestone: ---
Hi,
When building the qtbase `dev` branch with GCC 11, a bunch of warnings are
generated even in the presence of a ignoring pragma.
For a bit of context, in Qt there's a macro called Q_OBJECT that users can add
to their classes; this macro expands to a series of declarations, including a
couple of virtuals. These may raise -Wsuggest-override warnings, in user code,
so such warnings are suppressed via pragmas (as part of the Q_OBJECT macro
itself).
GCC 10 honors the pragmas and doesn't raise warnings, but GCC 11 doesn't honor
them, resulting in warnings like
include/QtCore/../../../src/corelib/kernel/qtmetamacros.h:159:32: error:
‘virtual const QMetaObject* QTextObject::metaObject() const’ can be marked
override [-Werror=suggest-override]
159 | virtual const QMetaObject *metaObject() const; \
| ^~~~~~~~~~
include/QtGui/../../../src/gui/text/qtextobject.h:62:5: note: in expansion
of macro ‘Q_OBJECT’
62 | Q_OBJECT
| ^~~~~~~~
include/QtCore/../../../src/corelib/kernel/qtmetamacros.h:160:19: error:
‘virtual void* QTextObject::qt_metacast(const char*)’ can be marked override
[-Werror=suggest-override]
160 | virtual void *qt_metacast(const char *); \
| ^~~~~~~~~~~
include/QtGui/../../../src/gui/text/qtextobject.h:62:5: note: in expansion
of macro ‘Q_OBJECT’
62 | Q_OBJECT
| ^~~~~~~~
And so on and so forth.
Now, the peculiarity of this bug is that if you disable the integrated
preprocessor via -no-integrated-cpp then everything works fine. Similarly, if
you take a preprocessed output and compile *that*, then no warnings are raised.
I therefore suspect a regression in the integrated preprocessor.
For this reason I'm actually unable to attach a testcase: a preprocessed output
compiles just fine. Please advise as of what kind of test I could do / provide
to help you track this one down.
If you wish to try and compile Qt yourself, then it's relatively easy:
1) clone git://code.qt.io/qt/qtbase.git , checkout dev
2) get a very recent CMake
3) mkdir build
4) (with GCC 11 in PATH, or force it via CC/CXX env) cmake -GNinja
-DCMAKE_BUILD_TYPE=Debug -DQT_BUILD_EXAMPLES_BY_DEFAULT=OFF
-DQT_BUILD_TESTS_BY_DEFAULT=OFF -DFEATURE_developer_build=ON ../path/to/qtbase
5) ninja
Upstream bug: https://bugreports.qt.io/browse/QTBUG-93360