Bug 39045 - uninitialized reference in struct with operator new is not erroring out
Summary: uninitialized reference in struct with operator new is not erroring out
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 39963 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-01-30 20:50 UTC by Alexey Veselovsky
Modified: 2011-09-29 22:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.3.3, 4.0.1, 4.5.0
Last reconfirmed: 2009-04-29 15:34:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Veselovsky 2009-01-30 20:50:39 UTC
g++ allows to exist not inited reference in this case:

struct X
{
   int &x;
};

int main()
{
    X* p_x = new X; // now there is not inited reference (p_x->x)
    // now we can try to use p_x->x
    std::cout << p_x->x << std::endl; // segmentation fault
    return 0;
}

There are no errors or warnings. Compilation is successfull. 

I have tested on g++ (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3).
Also it "works" on g++ 4.3.
Comment 1 Wolfgang Bangerth 2009-02-01 05:18:12 UTC
Confirmed.
Comment 2 Alexey Veselovsky 2009-02-01 09:17:47 UTC
I think it should be error, not warning. (comeau and ms vc claims it as error)
Comment 3 Andrew Pinski 2009-02-06 02:41:55 UTC
This is looks like PR 29039.
Comment 4 Andrew Pinski 2009-04-29 15:35:31 UTC
*** Bug 39963 has been marked as a duplicate of this bug. ***
Comment 5 Paolo Carlini 2011-09-29 22:55:30 UTC
Fixed in 4.6.x.