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

2024-12-19


968. Syntactic ambiguity of the attribute notation

Section: 9.12.1  [dcl.attr.grammar]     Status: CD2     Submitter: Daveed Vandevoorde     Date: 23 September, 2009

[Voted into WP at March, 2010 meeting as document N3063.]

The [[ ... ]] notation for attributes was thought to be completely unambiguous. However, it turns out that two [ characters can be adjacent and not be an attribute-introducer: the first could be the beginning of an array bound or subscript operator and the second could be the beginning of a lambda-introducer. This needs to be explored and addressed.

(See also issue 951.)

Proposed resolution (November, 2009):

Add the following paragraph at the end of 9.3.3 [dcl.ambig.res]:

Two consecutive left square bracket tokens shall appear only when introducing an attribute-specifier. [Note: If two consecutive left square brackets appear where an attribute-specifier is not allowed, the program is ill-formed even if the brackets match an alternative grammar production. —end note] [Example:

  int p[10];
  void f() {
    int x = 42;
    int(p[[x]{return x;}()]);  // Error: malformed attribute on a nested
                               // declarator-id and not a function-style cast of
                               // an element of p.
    new int[[]{return x;}()];  // Error even though attributes are not allowed
  }                            // in this context.

end example]