Title
Common nonterminal for expression and braced-init-list
Status
cd4
Section
8.6.5 [stmt.ranged]
Submitter
Daniel Krügler

Created on 2011-03-25.00:00:00 last changed 49 months ago

Messages

Date: 2015-10-15.00:00:00

[Moved to DR at the October, 2015 meeting.]

Date: 2015-05-15.00:00:00

Proposed resolution (May, 2015):

  1. Add a new production to the grammar in 9.4 [dcl.init] paragraph 1:

    • expr-or-braced-init-list:
        expression
        braced-init-list
  2. Change the grammar in 7.6.1 [expr.post] paragraph 1 as follows:

    • postfix-expression:
        primary-expression
        postfix-expression [ expression expr-or-braced-init-list ]
        postfix-expression [ braced-init-list ]
        postfix-expression ( expression-listopt )
        ...
  3. Change the grammar in 8.6 [stmt.iter] paragraph 1 as follows:

    • for-range-initializer:
        expression
        braced-init-list
        expr-or-braced-init-list
  4. Change 8.6.5 [stmt.ranged] paragraph 1 as follows:

  5. For a range-based for statement of the form

      for ( for-range-declaration : expression ) statement

    let range-init be equivalent to the expression surrounded by parentheses90

      ( expression )

    and for a range-based for statement of the form

      for ( for-range-declaration : braced-init-list ) statement

    let range-init be equivalent to the braced-init-list. In each case, a A range-based for statement is equivalent to

      {
      auto && __range = range-init for-range-initializer;
        for ( auto __begin = begin-expr,
                   __end = end-expr;
              __begin != __end;
              ++__begin ) {
          for-range-declaration = *__begin;
          statement
        }
      }
    

    where

    • if the for-range-initializer is an expression, it is regarded as if it were surrounded by parentheses (so that a comma operator cannot be reinterpreted as delimiting two init-declarators);

    • __range, __begin, and __end are variables defined for exposition only,; and

    • _RangeT is the type of the expression, and

    • begin-expr and end-expr are determined as follows:

      • if _RangeT the for-range-initializer is an expression of array type R, begin-expr and end-expr are __range and __range + __bound, respectively, where __bound is the array bound. If _RangeT R is an array of unknown size or an array of incomplete type, the program is ill-formed;

      • if _RangeT the for-range-initializer is a an expression of class type C, the unqualified-ids begin and end are looked up in the scope of class _RangeT C as if by class member access lookup (_N4868_.6.5.6 [basic.lookup.classref]), and if either (or both) finds at least one declaration, begin-expr and end-expr are __range.begin() and __range.end(), respectively;

      • otherwise, begin-expr and end-expr are begin(__range) and end(__range), respectively, where begin and end are looked up in the associated namespaces (6.5.4 [basic.lookup.argdep]). [Note: Ordinary unqualified lookup (6.5.3 [basic.lookup.unqual]) is not performed. —end note]

  6. Change the grammar of 8.7 [stmt.jump] paragraph 1 as follows:

    • jump-statement:
        break ;
        continue ;
        return expression expr-or-braced-init-listopt ;
        return braced-init-list ;
        goto identifier ;
  7. Change 8.7.4 [stmt.return] paragraph 2 as follows:

  8. The expression or braced-init-list expr-or-braced-init-list of a return statement is called its operand. A return statement...
  9. Change 12.4.5 [over.sub] paragraph 1 as follows:

  10. operator[] shall be a non-static member function with exactly one parameter. It implements the subscripting syntax

      postfix-expression [ expression expr-or-braced-init-list ]

    or

      postfix-expression [ braced-init-list ]

    Thus, a subscripting expression...

Date: 2012-09-24.00:00:00

It would be helpful to have a single grammar term for expression and braced-init-list, which often occur together in the text. In particular, 8.6.5 [stmt.ranged] paragraph 1 allows both, but the description of __RangeT refers only to the expression case; such errors would be less likely if the common term were available.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: dr -> cd4
2015-11-10 00:00:00adminsetmessages: + msg6070
2015-11-10 00:00:00adminsetstatus: ready -> dr
2015-05-25 00:00:00adminsetmessages: + msg5451
2015-05-25 00:00:00adminsetstatus: drafting -> ready
2011-03-25 00:00:00admincreate