Comma operator and rvalue conversion
7.6.20 [expr.comma]
Mike Miller

Created on 1999-12-20.00:00:00 last changed 228 months ago


Date: 2000-04-15.00:00:00

Proposed resolution (10/00):

Add the following as paragraph 3 of C.6.4 [diff.expr]:

5.16, 5.17, 5.18

Change: The result of a conditional expression, an assignment expression, or a comma expression may be an lvalue.
Rationale: C++ is an object-oriented language, placing relatively more emphasis on lvalues. For example, functions may return lvalues.
Effect on original feature: Change to semantics of well-defined feature. Some C expressions that implicitly rely on lvalue-to-rvalue conversions will yield different results. For example,

    char arr[100];
    sizeof(0, arr)
yields 100 in C++ and sizeof(char*) in C.
Difficulty of converting: Programs must add explicit casts to the appropriate rvalue.
How widely used: Rare.

Date: 2020-12-15.00:00:00


    char arr[100];

What does the sizeof expression return? According to 7.6.20 [expr.comma] paragraph 1, the comma operator yields an lvalue if the second argument is an lvalue. Since 7.3.3 [conv.array] paragraph 1 says that the array-to-pointer conversion yields an rvalue, it seems that sizeof should see an array type and give the answer 100. If so, the value of the sizeof expression would be different from that of the corresponding expression in C, but there is nothing in Annex Annex C [diff] to indicate that an incompatible change was intended.

Date User Action Args
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2000-11-18 00:00:00adminsetstatus: ready -> dr
2000-05-21 00:00:00adminsetmessages: + msg306
2000-05-21 00:00:00adminsetstatus: open -> ready
1999-12-20 00:00:00admincreate