I am getting Wnarrowing warnings produced from a SFINAE context when this code is used on gcc. Clang and MSVC do not produce those warnings on this code.
// check for constructibility from a specific type and copy assignable used in the parse detection
template <typename T, typename C> class is_direct_constructible {
template <typename TT, typename CC>
static auto test(int) -> decltype(TT{std::declval<CC>()}, std::is_move_assignable<TT>());
template <typename, typename> static auto test(...) -> std::false_type;
public:
static const bool value = decltype(test<T, C>(0))::value;
};
This is being used to check if we can construct a type from another type and then move into it from the newly constructed value.
I can disable the warnings around this code if need be but I would like to understand if there is something I can do differently in the code that wouldn't produce them in the first place.
The brace initialization is what is being done in the context this is used along with other conditions, but the warnings seem to be produced even if the overload that uses the brace initialization isn't chosen.
Werror is used in some contexts which causes a compilation failure otherwise this seems to compile and execute as I would expect, just with a bunch of warnings.
Say a class has a constructor
class classX
{
classX(char){}
...
}
then
is_direct_constructible<classX,int>::value
would evaluate to true but produce a warning on gcc.
Ideally narrowing conversions would produce a SFINAE failure but I haven't figured out any way to prevent that.
Short of that I need to get rid of the warnings around this code.
Aucun commentaire:
Enregistrer un commentaire