This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Weird template bug.


The code in the bottom produces segfault when I'm using copy template
function to
copy xtmpl object. If "while" is used - everything is ok. 

Besides in gcc 2.95.2 everything works fine. 
But in 2.96 20000410, and in 2.96 20000501 with -O2 and -O3 options it
fails.

system: linux-2.2.15, glibc-2.1.2

---
#include <iostream>
#include <algorithm>

template<int X>
class xtmpl {
  int storage[X];
public:
  int *begin() const { return const_cast<int*> (storage); }
  int *end() const { return const_cast<int*> (&storage[X]); }
  xtmpl<X> operator= (const xtmpl<X>& x) {
    /* this works :
    int *i = begin();
    int *j = x.begin();
    while (j != x.end()) {
       *i++ = *j++;
    }
    */

    /* copy does not: */
    copy (x.begin(), x.end(), begin());
    return *this;
  }
};


struct TestType {
  char x[10000];
  struct M {
    char x[10000];
    xtmpl<1000> z;
  } m[2];
};



int
main (int argc, char **argv)
{
  TestType x1, x2;

  cout << "before assignment\n" << flush;
  x1 = x2;
  cout << "after assignment\n" << flush;

} 






-- 
/ig, 
mailto:iggy@homepage.ru,
http://www.homepage.ru/~iggy

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]