http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49144

           Summary: [4.6/4.7 regression] miscompiled reverse_iterator?
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: d...@ubuntu.com


[forwarded from http://bugs.debian.org/PR627795]

seen with 4.6 r174102 and trunk r173903

The attached test program is supposed to print -42, and does so when compiled
with g++-4.4 or g++-4.5. However, it outputs random junk when compiled with
g++-4.6:

$ g++ -Wall -O2 test.cxx
$ ./a.out
31
$ ./a.out
207
$ ./a.out
79


#include <iostream>

int f()
{
    unsigned char data[3] = { 42, 42, 42 };
    unsigned char *begin = data;
    unsigned char *end = data + 3;
    std::reverse_iterator<unsigned char *> reversed(end);
    for (; begin < end; begin++, reversed++)
        if (*reversed != 42)
            return *reversed;
    return -42;
}

int main(int argc, char ** argv)
{
    std::cout << f() << "\n";
}

Reply via email to