【发布时间】:2012-10-27 19:23:03
【问题描述】:
以下代码:
#include <iostream>
#include <array>
using namespace std;
constexpr int N = 1000000;
constexpr int f(int x) { return x*2; }
typedef array<int, N> A;
template<int... i> struct F { static constexpr A f() { return A{{ ::f(i)... }}; } };
template<class A, class B> struct C {};
template<int... i, int... j> struct C<F<i...>, F<j...>> : F<i..., (sizeof...(i)+j)...>
{
using T = F<i..., (sizeof...(i)+j)...>;
};
template<int n> struct S : C<typename S<n/2>::T, typename S<n-n/2>::T> {};
template<> struct S<1> : F<0> { using T = F<0>; };
constexpr auto X = S<N>::f();
int main()
{
cout << X[3] << endl;
}
在-std=gnu++11 模式下的 GCC 4.7 中产生内部编译器错误。
$ g++ -std=gnu++11 test.cpp
g++-4.7.real: internal compiler error: Killed (program cc1plus)
出了什么问题?
【问题讨论】:
-
在 4.7.1 我有
cc1plus: out of memory allocating 1048576 bytes after a total of 401997824 bytes。看起来像一个编译器错误。 -
我在 4.7.2 并且有 32GB 的内存。这些都可以解释差异。
-
可能是因为这里有 8 GB 但是当减小
N的值时它会正确编译。