【问题标题】:Use decltype inside template parameter list to deduce the type of pointer to class member在模板参数列表中使用 decltype 来推断指向类成员的指针的类型
【发布时间】:2016-02-14 14:00:21
【问题描述】:

当我尝试实例化这样的模板时,GCC 给我一个“模板参数 2 无效”错误(请参阅using Check 行)。我很好奇我可以在模板参数列表之外使用decltype 获得指向成员的指针,但不能在其中(参见变量p2 的定义)。 Clang 确实编译了这段代码。这是 GCC 中的一个错误,还是这段代码实际上是无效的,而 Clang 的包容性太强了?

template <class T, T t> struct checker_template {};

struct S { int n; };

int main() {
  S s;
  constexpr auto p1 = &S::n;
  constexpr auto p2 = &decltype(s)::n;
  using Check = checker_template<int S::*, &decltype(s)::n>;
  return 0;
}

【问题讨论】:

  • 您选择不包含来自 GCC 的完整错误的任何特殊原因?
  • Bug,已在后备箱中修复。
  • @kfsone 这确实是唯一有意义的信息。
  • @T.C.您可能应该发布您的评论作为答案。谢谢。

标签: c++ templates c++11 gcc


【解决方案1】:

答案由 T.C. 提供。这确实是 GCC 的一个 bug。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    相关资源
    最近更新 更多