【问题标题】:Intel C++ compiler bug in member function overload resolution involving "using" alias?涉及“使用”别名的成员函数重载解析中的英特尔 C++ 编译器错误?
【发布时间】:2014-08-04 20:26:54
【问题描述】:
#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 标准的人都可以确认这确实是一个错误吗?

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

【问题讨论】:

标签: c++ c++11 compiler-bug icc


【解决方案1】:

您的示例(显然)格式正确。 §14.8.2.5/9 描述了在这种情况下如何执行扣除。

如果P 有一个包含&lt;T&gt;&lt;i&gt; 的表单,那么每个参数Pi 属于各自的模板参数列表PA的对应模板实参列表的对应实参Ai进行比较。 […]。如果Pi 是一个包扩展,则将Pi 的模式与每个A 的模板参数列表中的剩余参数。每次比较都会推导出模板参数包中后续位置的模板参数,该模板参数包由Pi 扩展。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    相关资源
    最近更新 更多