Bug 20531 - gcc should warn about undefined behaviour
Summary: gcc should warn about undefined behaviour
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2005-03-18 10:46 UTC by Pawel Sikora
Modified: 2005-03-19 13:18 UTC (History)
1 user (show)

See Also:
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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.