CWG Issue 2079 (original) (raw)

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

2025-11-05


2079.[[ appearing in a balanced-token-seq

Section: 9.13.1 [dcl.attr.grammar]Status: CD4Submitter: Jonathan CavesDate: 2015-02-03

[Adopted at the February, 2016 meeting.]

According to 9.13.1 [dcl.attr.grammar] paragraph 6,

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_]

In order to allow program fragments to appeae within attributes, this restriction should not apply within the_balanced-token-seq_ of an attribute.

Proposed resolution (September, 2015):

Change 9.13.1 [dcl.attr.grammar] paragraph 6 as follows:

Two consecutive left square bracket tokens shall appear only when introducing an attribute-specifier or within the balanced-token-seq of an attribute-argument-clause. [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, y[5]; int(p[[x] { return x; }()]); // error: invalid attribute on a nested // declarator-id and not a function-style cast of // an element of p. y[[] { return 2; }()] = 2; // error even though attributes are not allowed // in this context.

int i [[vendor::attr([[]])]]; // well-formed implementation-defined attribute. }

—_end example_]