Title
Unclear disambiguation of destructor and operator~
Status
cd4
Section
7.6.2.2 [expr.unary.op]
Submitter
Hubert Tong

Created on 2014-07-15.00:00:00 last changed 95 months ago

Messages

Date: 2015-05-15.00:00:00

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

Date: 2014-11-15.00:00:00

Proposed resolution (November, 2014):

Change 7.6.2.2 [expr.unary.op] paragraph 10 as follows:

The operand of ~ shall have integral or unscoped enumeration type; the result is the one's complement of its operand. Integral promotions are performed. The type of the result is the type of the promoted operand. There is an ambiguity in the unary-expression ~X(), where X is in the grammar when ~ is followed by a class-name or decltype-specifier. The ambiguity is resolved in favor of by treating ~ as a the unary complement operator rather than treating ~X as referring to as the start of an unqualified-id naming a destructor. [Note: Because the grammar does not permit an operator to follow the ., ->, or :: tokens, a ~ followed by a class-name or decltype-specifier in a member access expression or qualified-id is unambiguously parsed as a destructor name. —end note]
Date: 2014-07-15.00:00:00

There is language in 7.6.2.2 [expr.unary.op] paragraph 10 to disambiguate destructor references from references to operator~:

There is an ambiguity in the unary-expression ~X(), where X is a class-name or decltype-specifier. The ambiguity is resolved in favor of treating ~ as a unary complement rather than treating ~X as referring to a destructor.

However, it is not clear whether this is intended to apply to an example like,

  struct X {
    X(int);
    operator int();
    void foo() {
      ~X(0);
    }
  };

where the form of reference has an apparent argument.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-11-10 00:00:00adminsetstatus: dr -> drwp
2015-05-25 00:00:00adminsetmessages: + msg6046
2015-05-25 00:00:00adminsetstatus: tentatively ready -> dr
2014-11-24 00:00:00adminsetmessages: + msg5164
2014-07-15 00:00:00admincreate