Same issue as https://github.com/woboq/verdigris/pull/48. When I define a W_OBJECT in an anonymous namespace, building using Clang (MSVC ABI) on Windows, I get the following kind of warning:
C:/Users/nyanpasu64/code/exotracker-cpp/src/gui/instrument_list.cpp:31:5: warning: unused variable 'W_UnscopedName' [-Wunused-const-variable]
W_OBJECT(InstrumentListModel)
^
C:/Users/nyanpasu64/code/exotracker-cpp/3rdparty\verdigris/wobjectdefs.h:771:5: note: expanded from macro 'W_OBJECT'
W_OBJECT_COMMON(TYPE) \
^
C:/Users/nyanpasu64/code/exotracker-cpp/3rdparty\verdigris/wobjectdefs.h:752:31: note: expanded from macro 'W_OBJECT_COMMON'
static constexpr auto W_UnscopedName = w_internal::viewLiteral(#TYPE); /* so we don't repeat it in W_CONSTRUCTOR */ \
^
This macro turns into a static member variable, declared in a QObject subclass's body, so you can't use Q_UNUSED (which is only valid in functions).
Solutions
[[maybe_unused]] static constexpr auto W_UnscopedName works in my testing, but unfortunately this is C++17-only and Verdigris supports C++14 as well.
Q_DECL_UNUSED static constexpr auto W_UnscopedName also works, but Q_DECL_UNUSED seems to be broken in some Clang configurations: https://bugreports.qt.io/browse/QTBUG-69424
Same issue as https://github.com/woboq/verdigris/pull/48. When I define a
W_OBJECT
in an anonymous namespace, building using Clang (MSVC ABI) on Windows, I get the following kind of warning:https://github.com/woboq/verdigris/blob/fda6e91391c2e3e58abd4fd996803259fc54905f/src/wobjectdefs.h#L752
This macro turns into a static member variable, declared in a QObject subclass's body, so you can't use
Q_UNUSED
(which is only valid in functions).Solutions
[[maybe_unused]] static constexpr auto W_UnscopedName
works in my testing, but unfortunately this is C++17-only and Verdigris supports C++14 as well.Q_DECL_UNUSED static constexpr auto W_UnscopedName
also works, butQ_DECL_UNUSED
seems to be broken in some Clang configurations: https://bugreports.qt.io/browse/QTBUG-69424