涉及“使用”别名的成员函数重载解析中的Intel C ++编译器错误?

old
#include <cstddef>

template<typename T, T... Is>
struct Bar { };

template<size_t... Is>
using Baz = Bar<size_t, Is...>;

struct Foo {
  template<size_t... Is>
  void NoAlias(Bar<size_t, Is...>) { }

  template<size_t... Is>
  void Alias(Baz<Is...>) { }
};

template<typename T, T... Is>
void foo(Bar<T, Is...>) { }

template<size_t... Is>
void bar(Bar<size_t, Is...>) { }

int main() {
  // All these work fine
  foo(Bar<size_t, 4, 2>());
  foo(Baz<4, 2>());
  bar(Bar<size_t, 4, 2>());
  bar(Baz<4, 2>());
  Foo().NoAlias(Bar<size_t, 4, 2>());
  Foo().NoAlias(Baz<4, 2>());

  // But these two give error on ICPC (ICC) 14.0.2:
  //   no instance of function template "Foo::Alias" matches the argument list
  // Note the only difference between NoAlias and Alias is (not) using the alias
  // for the member function parameter
  Foo().Alias(Bar<size_t, 4, 2>());
  Foo().Alias(Baz<4, 2>());

  return 0;
}

ICC 14.0.2给出错误:

$ icc -std=c++11 -Wall -pedantic -pthread -o .scratch{-,.}cpp && ./.scratch-cpp

.scratch.cpp(36): error: no instance of function template "Foo::Alias" matches the argument list
            argument types are: (Bar<size_t, 4UL, 2UL>)
            object type is: Foo
    Foo().Alias(Bar<size_t, 4, 2>());
          ^

.scratch.cpp(37): error: no instance of function template "Foo::Alias" matches the argument list
            argument types are: (Baz<4UL, 2UL>)
            object type is: Foo
    Foo().Alias(Baz<4, 2>());
          ^

但是,它可以同时使用GCC 4.8和Clang 3.4.2进行编译。(在64位Linux上测试。)

熟悉C ++ 11标准的任何人都可以确认这确实是一个错误吗?

另外,是否有一个简单的基于预处理器的解决方法?

哥伦布

您的示例(显然)格式正确。第14.8.2.5/9节介绍了这种情况下的演绎方式。

如果P具有包含<T>的形式<i>,则将各个模板参数列表的每个参数Pi与的模板参数列表P的对应参数Ai进行比较A[…]。如果Pi是压缩扩展,则将Pi的模式与的模板参数列表中的每个剩余参数进行比较A每个比较都推导模板参数包中由Pi扩展的后续位置的模板参数

此外,您的代码正在本机上使用15.0.3版进行编译。因此,升级编译器应该可以解决此问题。我看不到其他简单的解决方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章