[Bug libstdc++/11584] New: ios::iword() fails to zero-initialize storage on failure

sebor at roguewave dot com gcc-bugzilla@gcc.gnu.org
Fri Jul 18 23:10:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: ios::iword() fails to zero-initialize storage on failure
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com
                CC: gcc-bugs at gcc dot gnu dot org

According to 27.4.2.5, p3, of ISO/IEC 14882:2003, the program below is expected
to exit with the status of 0. It exits with a non-0 status when compiled with
gcc 3.2.

Regards
Martin

#include <stdlib.h>
#include <iostream>
#include <new>

int new_fails;

void* operator new (size_t n)
{
    if (new_fails)
        throw std::bad_alloc ();

    return malloc (n);
}

void operator delete (void *p) { free (p); }
void* operator new[] (size_t n) { return operator new (n); }
void operator delete[] (void *p) { operator delete (p); }

int main ()
{
    const int i = std::ios::xalloc ();

    new_fails = 1;

    std::cout.iword (i) = 0xdeadbeef;

    return std::cout.iword (i);
}



More information about the Gcc-bugs mailing list