Title
Comma operator and rvalue conversion
Status
tc1
Section
7.6.20 [expr.comma]
Submitter
Mike Miller

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

Messages

Date: 2000-04-15.00:00:00

Proposed resolution (10/00):

Add the following as paragraph 3 of C.7.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: 2022-02-18.07:47:23

Given

    char arr[100];
    sizeof(0,arr);

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 Clause Annex C [diff] to indicate that an incompatible change was intended.

History
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