【发布时间】:2017-04-18 10:37:35
【问题描述】:
考虑一个例子:
#include <utility>
template <class... Ts>
struct pack {
static constexpr std::size_t size = sizeof...(Ts);
};
template <class P, class = std::make_index_sequence<P::size>>
struct ipack;
template <class... Ts, std::size_t... Is>
struct ipack<pack<Ts...>, std::index_sequence<Is...>> {
static constexpr std::size_t size = sizeof...(Ts);
};
template <class IP, class = std::make_index_sequence<IP::size>>
struct vpack;
template <class... Ts, std::size_t... Is>
struct vpack<ipack<pack<Ts...>>, std::index_sequence<Is...>> {
static constexpr std::size_t size = sizeof...(Ts);
};
int main() {
vpack<ipack<pack<int, int, int>>> vp;
static_cast<void>(vp);
}
clang reports 有问题:
prog.cc:29:39: error: implicit instantiation of undefined template 'vpack<ipack<pack<int, int, int>, std::__1::integer_sequence<unsigned long, 0, 1, 2> >, std::__1::integer_sequence<unsigned long, 0, 1, 2>
vpack<ipack<pack<int, int, int>>> vp;
^
gcc does not share 铿锵情愫。哪个编译器是对的?上面的代码在某种程度上是不是格式错误?
【问题讨论】:
-
我无法使用 Apple 的 clang
Apple LLVM version 8.1.0 (clang-802.0.41)重现您的编译错误——不确定这对应于哪个正常版本的 clang。编译后的二进制文件似乎也可以正常工作;例如,您的示例中的vp.size等于 3。 -
@jwimberley 所以你说这可能是 wandbox 的 clang 版本的问题?
-
我复制并粘贴了 WandBox 使用的编译命令,
clang++ prog.cc -Wall -Wextra -O2 -march=native -std=c++14 -pedantic(一些设置从您的原始帖子更改,但编译器错误相同)。这再次使 Apple Clang 没有错误。 -
这同样是 WandBox 的 libc++ 或它使用的任何库的问题吗?可能模板与其库中定义的
std::integer_sequence不匹配... -
它与 stdlib 无关(@jwimberley),它与 Clang 版本有关; 3.8.1 compiles cleanly,3.9+ 没有。所以,这要么是回归,要么是错误修复——问题是哪个。如果是后者并且需要解决方法,here 很简单。