In clang, I get this warning
warning: inline function 'detail::selector<2, int>::select' is not defined [-Wundefined-inline]
static constexpr auto select(T const&) -> std::integral_constant<int, Which>;
^
note: used here
static_assert( decltype(Selector::select(int()))::value == 2, "");
^
in the code below.
Is function definition impractical here? (I strongly believe that this does not matter here and in my application, since it was used in an invaluable context, in std :: enable_if).
Now I wonder when the compiler thinks it should issue a warning.
#include <type_traits>
namespace detail {
template <int Which, typename...> struct selector;
template <int Which>
struct selector<Which> {
static constexpr void select();
};
template <int Which, typename T, typename... Ts>
struct selector<Which, T, Ts...> : selector<Which+1, Ts...>
{
using selector<Which+1, Ts...>::select;
static constexpr auto select(T const&) -> std::integral_constant<int, Which>;
};
}
int main(int argc, const char * argv[])
{
using Selector = detail::selector<0, char, short, int>;
static_assert( decltype(Selector::select(int()))::value == 2, "");
return 0;
}
Edit:
Notes:
gcc-4.8.1 on ideone.com does not display a warning.
The easiest way to get rid of the warning is to provide an implementation, for example:
static constexpr auto select(T const&)
-> std::integral_constant<int, Which>
{ return {}; }
(thanks @Yakk)
Decision
@Filip Roséen, constexpr inline, . , , , clang ( ). clang , constexpr . constexpr ( @Yakk).