[g++] -O2 and signed/unsigned char conversion
Linus Nordberg
linus@swox.se
Mon Jan 29 08:23:00 GMT 2001
#include <vector>
#include <iostream>
/*
vector<unsigned char>::push_back() with postincremented dereferenced
pointer to signed char and -O2 is bad.
Reproducable with
2.95.2 19991024 (release)
Not reproducable with
egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
---
$ uname -a
FreeBSD host 4.1-RELEASE FreeBSD 4.1-RELEASE #0: Tue Jan 2 09:48:24 CET 2001 root@host:/usr/src/sys/compile/HOST i386
$ which g++
/usr/bin/g++
$ g++ -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)
$ g++ -Wall -O2 -g push_back_bug.cpp -lstdc++ -o push_back_bug
$ ./push_back_bug
bc
$ g++ -Wall -g push_back_bug.cpp -lstdc++ -o push_back_bug
$ ./push_back_bug
ab */
int
main()
{
vector <unsigned char> ucv; // NOTE: unsigned char
const char* src = "abc"; // NOTE: signed char
ucv.push_back(*src++);
ucv.push_back(*src++);
cout << ucv[0] << ucv[1] << endl;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: push_back_bug.ii
Type: text/x-c++
Size: 136255 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20010129/0984961c/attachment.bin>
More information about the Gcc-bugs
mailing list