C ++ 11:g ++ - 4.7内部编译器错误 [英] C++11: g++-4.7 internal compiler error

查看:127
本文介绍了C ++ 11:g ++ - 4.7内部编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码:

#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;
}

中产生GCC 4.7中的内部编译器错误 - std = gnu ++ 11 模式。

$ g++ -std=gnu++11 test.cpp
g++-4.7.real: internal compiler error: Killed (program cc1plus)

推荐答案

似乎你的程序需要不合理的内存量(可能是因为模板扩展太多)。

It seems that your program requires an unreasonable amount of memory (perhaps because of too many template expansions).

使用最近的 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

(这是在Debian / Sid / AMD64与i3770K英特尔处理器& 16Gb RAM)

(this on Debian/Sid/AMD64 with i3770K intel processor & 16Gb RAM)

我得到:

  % 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

你编程的很多内存是不合理的。

So it seems that template expansion requires so much memory that you program is not reasonable.

我不确定是否会被接受为GCC错误。 C ++ tenplate宏展开是已知的图灵完成,你只是打在墙上。而且GCC树干确实报告了一个致命的,但是可以理解的错误。

I am not sure that would be accepted as a GCC bug. C++ tenplate macroexpansion is known to be Turing complete, and you just hit the wall. And the GCC trunk does report a fatal, but understandable, error.

故事的道德可能是 setrlimit(2)(具有与系统和硬件兼容的限制),可能使用 limit zsh内置或 ulimit bash内置。

The moral of the story might be to setrlimit(2) appropriately (with limits compatible with your system and hardware), perhaps using limit zsh builtin or ulimit bash builtin.

这篇关于C ++ 11:g ++ - 4.7内部编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆