[英]Intel C++ compiler bug in member function overload resolution involving “using” alias?
#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 gives error: 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>());
^
However, it compiles with both GCC 4.8 and Clang 3.4.2. 但是,它与GCC 4.8和Clang 3.4.2一起编译。 (Tested on a 64-bit Linux.)
(在64位Linux上测试过。)
Can anybody who is well acquainted with the C++11 standard confirm this is indeed a bug? 任何熟悉C ++ 11标准的人都能确认这确实是一个错误吗?
Also, is there an easy preprocessor-based workaround? 此外,是否有一个简单的基于预处理器的解决方法?
Your example is (clearly) well-formed. 你的例子(显然)格式正确。 §14.8.2.5/9 describes how deduction is performed in this case.
§14.8.2.5/ 9描述了在这种情况下如何进行演绎。
If
P
has a form that contains<T>
or<i>
, then each argumentP
i of the respective template argument listP
is compared with the corresponding argumentA
i of the corresponding template argument list ofA
.如果
P
具有包含<T>
或<i>
,则将相应模板参数列表P
每个参数P
i与A
的对应模板参数列表的对应参数A
i进行A
。 […].[...]。 If
P
i is a pack expansion, then the pattern ofP
i is compared with each remaining argument in the template argument list ofA
.如果
P
i是包扩展,则将P
i的模式与A
的模板参数列表中的每个剩余参数进行A
。 Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded byP
i .每个比较推导出由
P
i扩展的模板参数包中的后续位置的模板参数。
Moreover, your code is compiling with version 15.0.3 on my machine. 此外,您的代码正在我的机器上使用15.0.3版进行编译。 Hence upgrading the compiler should fix the issue.
因此升级编译器应解决问题。 I can't see another simple workaround.
我看不到另一种简单的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.