Bug 20531

Summary: gcc should warn about undefined behaviour
Product: gcc Reporter: Pawel Sikora <pawel_sikora>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: enhancement CC: gcc-bugs
Priority: P2 Keywords: diagnostic
Version: 4.0.0   
Target Milestone: ---   
Host: i686-pld-linux Target: i686-pld-linux
Build: i686-pld-linux Known to work:
Known to fail: Last reconfirmed: 2005-03-18 13:44:52

Description Pawel Sikora 2005-03-18 10:46:12 UTC
volatile struct {
    int x, y;
} s;

int foo()
{
    return (s.x > s.y);   // undefined behavior:
                          // the order of volatile accesses
                          // is undefined in this statment
}
Comment 1 Andrew Pinski 2005-03-18 13:44:52 UTC
Confirmed.
Comment 2 Joseph S. Myers 2005-03-19 13:18:03 UTC
I see no undefined behavior here.  The order is unspecified, not undefined,
and there is nothing more wrong with accessing two volatile objects between
sequence points than there would be in (s.x = 1) + (s.y = 2) modifying
both objects (volatile or not) without an intervening sequence point.