This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Weird template bug.
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Weird template bug.
- From: Iggy Veresov <iggy at homepage dot ru>
- Date: Sun, 21 May 2000 17:23:57 +0000
- Organization: Chaos Hack Labz.
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