【发布时间】:2018-09-07 15:08:43
【问题描述】:
鉴于此 C++11 代码:
#include <type_traits>
enum Enum { EnumValue };
template <typename>
struct Pred { constexpr static bool const value = true; };
template <
typename T,
typename ::std::enable_if<
Pred<T>::value,
Enum
>::type = EnumValue>
class Huh {};
template <typename T>
constexpr bool f(Huh<T> const &) noexcept { return true; }
static_assert(f(Huh<int>()), "");
我从 GCC 7.3.0 收到以下错误消息:
test.cpp:19:27: error: no matching function for call to 'f(Huh<int>)'
static_assert(f(Huh<int>()), "");
^
test.cpp:17:16: note: candidate: template<class T> constexpr bool f(const Huh<T>&)
constexpr bool f(Huh<T> const &) noexcept { return true; }
^
test.cpp:17:16: note: template argument deduction/substitution failed:
test.cpp:19:27: note: template argument '(type)0' does not match 'EnumValue'
static_assert(f(Huh<int>()), "");
^
如果我使用int 和0 而不是Enum 和EnumValue,错误就消失了。 为什么这会因枚举而失败?
【问题讨论】:
-
看起来像一个错误。 gcc 8.x+ 和 clang 一样编译
-
它为我编译了 G++ 8.2.1 和 Clang++ 6.0.1。也许这是一个编译器错误。
-
使用 MinGW g++ 7.3.0 转载。看起来它无法处理两个级别的模板。设法处理一个级别。
-
有没有人知道如何在损坏的 GCC 版本上解决这个问题,同时保留枚举?
标签: c++ c++11 g++ compiler-bug