Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused W_UnscopedName warnings when defining W_OBJECT in anonymous namespaces #85

Open
nyanpasu64 opened this issue Mar 15, 2021 · 1 comment

Comments

@nyanpasu64
Copy link

Same issue as #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 */ \
                              ^

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

@ogoffart
Copy link
Member

Q_DECL_UNUSED should work as it is used within Qt itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants