C++ Clang emit warning about unused template variable
Considering an unused template variable definition, such as this one :
template <typename T, typename = void>
struct is_complete : std::false_type {};
template <typename T>
struct is_complete<T, std::void_t<decltype(sizeof(T))>>
: std::true_type {};
template <typename T>
constexpr static inline auto is_complete_v = is_complete<T>::value;
Here, Clang emit a warning about unused is_complete_v variable, which seems wrong to me.
Why would such variable symbol be instanciated at all, if unused ? Perhaps I'm missing a point.
warning: unused variable 'is_complete_v' [-Wunused-const-variable]
static inline constexpr auto is_complete_v = is_complete_v<T>::value;
The case is, other compiliers like GCC does not emit any warning.
Which IMOO makes sens, as the symbol is not resolved.
I could fix up all the codebases I'm working with using either :
template <typename T>
#if __clang__
[[maybe_unused]]
#endif
constexpr static inline auto is_complete_v = is_complete<T>::value;
Or by disabling -Wunused-const-variable,
But I wonder if :
- Is there a cleaner way to achieve this ?
- Is this a normal behavior ?