Dear developers.

I guess it is gcc bug. But for the case that it a libary bug can any one forward it to the boost develops, because I do not understand how to use their bug tracking system.

I have found a strange limitation for the size of an array. The error
is the same both for boost 1.36 and for the array in gcc 4.3.2 (and in
the gcc 4.4 snapshot I use). I am almost sure that it is a bug of gcc
and not of the array implementation.

Here is the code.

#include<array>
using namespace std;


int main () {
  array<unsigned int, (1<<22)> a; // Create a big array

  a[(1<<22)-13]=0;  // This give a segmantation fault
}

In contrast a C-array works fine.

int main () {
  unsigned int  a[1<<22];

  a[(1<<22)-13]=0;  // This give a segmantation fault
}

Since the naturale implementation of the array class is just a wrapper
around the C-style array this is very strange.

I tryed to track down the bug. You use the following implementation:

  template<typename T, unsigned int n> class array {
    T C[n];

  public:
    typedef unsigned int size_type;
    T& operator[](size_type p) {
      return C[p];
    }
  };

If we change the C[n] to an explicite new it works fine.

  template<typename T, unsigned int n> class array {
    T* C;

  public:
    typedef unsigned int size_type;
    array() {
      C = new T[n];
    }
    T& operator[](size_type p) {
      return C[p];
    }
  };

It seams that this resolves the bug. But I can not explain why.
I tested the code with the intel compiler and it works fine for both
implementations. So it seams that it is a gcc bug, that the first
solution do not work. What happens here?

Kind regards
     Andreas Klein

Reply via email to