Title
What makes side effects “different” from one another?
Status
cd1
Section
6.9.1 [intro.execution]
Submitter
James Widman

Created on 2007-07-26.00:00:00 last changed 161 months ago

Messages

Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting.]

Date: 2008-03-15.00:00:00

Proposed resolution (March, 2008):

Change 6.9.1 [intro.execution] paragraph 16 as follows:

...If a side effect on a scalar object is unsequenced relative to either a different another side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. [Example:

    void f(int, int);
    void g(int i, int* v) {
        i = v[i++];         // the behavior is undefined
        i = 7, i++, i++;    // i becomes 9

        i = ++i + 1;        // the behavior is undefined
        i = i + 1;          // the value of i is incremented

        f(i = -1, i = -1);  // the behavior is undefined
    }

end example] When calling...

Date: 2007-07-26.00:00:00

Is the behavior undefined in the following example?

    void f() {
         int n = 0;
         n = --n;
    }

6.9.1 [intro.execution] paragraph 16 says,

If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.

It's not clear to me whether the two side-effects in n=--n are “different.” As far as I can tell, it seems that both side-effects involve the assignment of -1 to n, which in a sense makes them non-“different.” But I don't know if that's the intent. Would it be better to say “another” instead of “a different?”

On a related note, can we include this example to illustrate?

    void f( int, int );
    void g( int a ) { f( a = -1, a = -1 ); } // Undefined?
History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1803
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetstatus: review -> ready
2008-05-18 00:00:00adminsetmessages: + msg1636
2008-05-18 00:00:00adminsetstatus: drafting -> review
2007-10-09 00:00:00adminsetstatus: open -> drafting
2007-07-26 00:00:00admincreate