Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


324. Can "&" be applied to assignment to bit-field?

Section:7.6.2.2  [expr.unary.op]    Status:CD1    Submitter:Alasdair Grant    Date:27 Nov 2001

[Voted into WP at October 2003 meeting.]

An assignment returns an lvalue for its left operand. If thatoperand refers to a bit field, can the "&" operator beapplied to the assignment? Can a reference be bound to it?

  struct S { int a:3; int b:3; int c:3; };  void f()  {    struct S s;    const int *p = &(s.b = 0);     // (a)    const int &r = (s.b = 0);      // (b)          int &r2 = (s.b = 0);     // (c)  }

Notes from the 4/02 meeting:

The working group agreed that this should be an error.

Proposed resolution (October 2002):

In 7.6.2.3 [expr.pre.incr] paragraph 1(prefix "++" and "--" operators), change

The value is the new value of the operand; it is an lvalue.
to
The result is the updated operand; it is an lvalue, and it is abit-field if the operand is a bit-field.

In 7.6.16 [expr.cond] paragraph 4("?" operator), add the indicated text:

If the second and third operands are lvalues and havethe same type, the result is of that type and is an lvalueand it is a bit-field if the second or the thirdoperand is a bit-field, or if both are bit-fields.

In 7.6.19 [expr.assign] paragraph 1 (assignment operators)add the indicated text (the original text isas updated by issue 221, which is DR but not in TC1):

The assignment operator (=) and the compound assignmentoperators all group right-to-left. All require a modifiable lvalue astheir left operand and return an lvalue with the type and value ofthe left operand after the assignment has taken place.The resultin all cases is a bit-field if the left operand is a bit-field.

Note that issue 222 adds (non-conflicting) text at the end ofthis same paragraph (7.6.19 [expr.assign] paragraph 1).

In 7.6.20 [expr.comma] paragraph 1 (comma operator), change:

The type and value of the result are the type and value of the rightoperand; the result is an lvalue if its right operand is.
to
The type and value of the result are the type and value of the rightoperand; the result is an lvalue if the right operand is an lvalue,and is a bit-field if the right operand is an lvalue and a bit-field.

Relevant related text (no changes required):

7.6.2.2 [expr.unary.op] paragraph 4:

The operand of& shall not be a bit-field.

9.5.4 [dcl.init.ref] paragraph 5, bullet 1, sub-bullet 1 (regarding bindinga reference to an lvalue):

... is an lvalue (but is not a bit-field) ...




[8]ページ先頭

©2009-2026 Movatter.jp