[Development] Q_OBJECT and "override"
Christian Kandeler
christian.kandeler at theqtcompany.com
Thu Jun 4 14:12:05 CEST 2015
Hi,
as anyone who uses clang has probably already noticed, this compiler has
recently added "-Winconsistent-missing-override" to the collection of
flags enabled via "-Wall". As a result, you now get literally thousands
of warnings when building any non-trivial Qt project. This is because
the expansion of the Q_OBJECT macro contains virtual overrides that are
not marked with the "override" keyword, so all QObject-derived classes
using Q_OBJECT and making use of the "override" keyword will trigger
this warning. Adding the keyword in the Q_OBJECT definition does not
help in itself, as now all derived classes *not* using "override" would
trigger the warning.
So how to deal with this?
1) Add "override" (or rather Q_DECL_OVERRIDE) to the definition of
Q_OBJECT *and* all QObject-derived classes in Qt.
Pros: Is the correct solution.
Cons: Tedious work, will introduce some noise into the git history.
2) Remove "override" from all QObject-derived classes in Qt.
Pros: Less work than 1)
Cons: Entirely wrong. Discourages developers from using "override" in
their code, for a start.
3) Explicitly disable the warning in the clang mkspecs.
Pros: Easy to do.
Cons: Users might want to enable the warning, but they can't, as they
will then drown in warnings from our headers.
4) Let users deal with the problem by making them turn the warning off.
Pros: Even easier to do.
Cons: See 3). Also seems very lazy.
Opinions?
Christian
More information about the Development
mailing list