【发布时间】:2016-10-29 22:36:17
【问题描述】:
为了理解another question,我已经简化了示例,得到以下代码。
template <bool>
struct foo
{
template <typename T>
auto bar (int i)
{ return i; }
};
template <>
template <typename T>
auto foo<true>::bar (int i)
{ return i; }
int main()
{
return 0;
}
g++ 4.9.2 编译没有问题; clang++ 3.5 报如下错误
tmp_003-14,gcc,clang.cpp:12:20: error: out-of-line definition of 'bar' does not
match any declaration in 'foo<true>'
auto foo<true>::bar (int i)
^~~
用int 替换两个auto 返回值之一,没有变化:g++ compile 和clang++ 给出错误。将auto 替换为int,错误消失。
template <typename T> 部分很重要,因为以下代码在两个编译器上都没有问题
template <bool>
struct foo
{
auto bar (int i)
{ return i; }
};
template <>
auto foo<true>::bar (int i)
{ return i; }
int main()
{
return 0;
}
我的问题很明显:谁是对的?
g++ 还是 clang++?
我认为 g++ 是正确的,这是来自 clang++ 的错误,但我要求确认。
ps:对不起,我的英语不好。
【问题讨论】:
-
试试 gcc 6.1 和 clang 3.8 ..
-
这是一个 Clang 问题。它适用于 3.8:godbolt.org/g/JkCJ6l
标签: c++ templates c++14 clang++ auto