Title
Syntactic ambiguities with final
Status
cd3
Section
Clause [11] [class]
Submitter
Johannes Schaub

Created on 2011-05-14.00:00:00 last changed 90 months ago

Messages

Date: 2013-04-15.00:00:00

[Moved to DR at the April, 2013 meeting.]

Date: 2012-10-15.00:00:00

Proposed resolution (October, 2012):

  1. Change 5.10 [lex.name] paragraph 2 as follows:

  2. The identifiers in Table 3 have a special meaning when appearing in a certain context. When referred to in the grammar, these identifiers are used explicitly rather than using the identifier grammar production. Unless otherwise specified, any ambiguity as to whether a given identifier has a special meaning is resolved to interpret the token as a regular identifier.
  3. Change Clause 11 [class] paragraph 3 as follows:

  4. If a class is marked with the class-virt-specifier final and it appears as a base-type-specifier in a base-clause (Clause 11.7 [class.derived]), the program is ill-formed. Whenever a class-key is followed by a class-head-name, the identifier final, and a colon or left brace, final is interpreted as a class-virt-specifier. [Example:

      struct A;
      struct A final {};      // OK: definition of struct A,
                              // not value-initialization of variable final
    
      struct X {
       struct C { constexpr operator int() { return 5; } };
       struct B final : C{};  // OK: definition of nested class B,
                              // not declaration of a bit-field member final
      };
    

    end example]

Date: 2012-09-24.00:00:00

The ambiguity in an example like

  struct A final { };

is resolved by 5.10 [lex.name] paragraph 2 to be the declaration of a variable named final:

any ambiguity as to whether a given identifier has a special meaning is resolved to interpret the token as a regular identifier.

Similarly, in an example like

  struct C { constexpr operator int() { return 5; } };
  struct A {
   struct B final : C{};
  };

final is taken as the name of a bit-field member rather than as the name of a nested class.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetstatus: ready -> dr
2012-11-03 00:00:00adminsetstatus: review -> ready
2012-09-24 00:00:00adminsetmessages: + msg3891
2012-09-24 00:00:00adminsetmessages: + msg3890
2012-09-24 00:00:00adminsetstatus: ready -> review
2012-02-27 00:00:00adminsetstatus: tentatively ready -> ready
2012-01-17 00:00:00adminsetstatus: review -> tentatively ready
2011-05-14 00:00:00admincreate