为什么SFINAE没有给出增加bool的正确结果?

时间:2018-06-24 16:29:00

标签: c++ sfinae typetraits

我这样写了一个is_incrementable特质:

#include <type_traits>

template <typename T, typename = void>
struct is_incrementable : std::false_type {};

template <typename T>
struct is_incrementable<T, std::void_t<decltype(++std::declval<T&>())>>
    : std::true_type {};

template <typename T>
constexpr bool is_incrementable_v = is_incrementable<T>::value;

当我使用bool并将其应用于-std=c++17时,它返回true

// This compiles
static_assert(is_incrementable_v<bool>, "");

但是在c ++ 17下不允许递增bool。确实,如果我尝试这样做,则会出现错误:

bool b = false;
++b;

导致:

error: ISO C++17 does not allow incrementing expression of type bool [-Wincrement-bool]

当编译器显然不允许bool时,为什么SFINAE报告webpack.config.js是可递增的?

编译器资源管理器:https://godbolt.org/g/DDFYBf

0 个答案:

没有答案