以下代码:
#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)哪里出了问题?
发布于 2012-10-28 05:13:08
您的程序似乎需要不合理的内存量(可能是因为太多的模板扩展)。
使用最新的g++-trunk:
gcc version 4.8.0 20121026 (experimental) [trunk revision 192860] (GCC) 具有以下zsh限制:
% limit
cputime unlimited
filesize unlimited
datasize 15000MB
stacksize 8MB
coredumpsize 400MB
memoryuse 15000MB
maxproc 128166
descriptors 1024
memorylocked 64kB
addressspace 16000MB
maxfilelocks unlimited
sigpending 128166
msgqueue 819200
nice 0
rt_priority 0
rt_time unlimited(这是在采用i3770K英特尔处理器和16 on内存的Debian/Sid/AMD64上)
我得到了:
% time g++-trunk -std=gnu++11 andrew.cc -o andrew
virtual memory exhausted: Cannot allocate memory
g++-trunk -std=gnu++11 andrew.cc -o andrew :
108.25s user 3.28s system 89% cpu 2:03.98 total因此,模板扩展似乎需要太多的内存,以至于你的程序是不合理的。
我不确定这是否会被接受为一个GCC的bug。众所周知,C++模板的宏扩展是图灵完成的,您只是碰壁了。而GCC后备箱确实报告了一个致命但可以理解的错误。
这个故事的寓意可能是适当地使用setrlimit(2) (具有与您的系统和硬件兼容的限制),也许使用limit zsh内置或ulimit bash内置。
发布于 2012-10-28 03:30:22
一个内部错误意味着你遇到了一个编译器错误。
https://stackoverflow.com/questions/13103396
复制相似问题