Title
Problems in decltype specification and examples
Status
cd1
Section
9.2.9.3 [dcl.type.simple]
Submitter
Daveed Vandevoorde

Created on 2007-08-16.00:00:00 last changed 161 months ago

Messages

Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting.]

Date: 2007-10-15.00:00:00

Proposed Resolution (October, 2007):

Change 9.2.9.3 [dcl.type.simple] paragraph 4 as follows:

The type denoted by decltype(e) is defined as follows:

  • if e is an id-expression or a class member access (7.6.1.5 [expr.ref]), decltype(e) is the type of the entity named by e. If there is no such entity, or if e names a set of overloaded functions, the program is ill-formed;

  • otherwise, if e is a function call (7.6.1.3 [expr.call]) or an invocation of an overloaded operator (parentheses around e are ignored), decltype(e) is the return type of that the statically chosen function;

  • otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e;

  • otherwise, decltype(e) is the type of e.

The operand of the decltype specifier is an unevaluated operand (clause Clause 7 [expr]).

[Example:

    const int&& foo();
    int i;
    struct A { double x; };
    const A* a = new A();
    decltype(foo()) x1;      // type is const int&&
    decltype(i) x2;          // type is int
    decltype(a->x) x3;       // type is double
    decltype((a->x)) x4;     // type is const double&

end example]

Date: 2007-08-16.00:00:00

The second bullet of 9.2.9.3 [dcl.type.simple] paragraph 4 reads,

  • otherwise, if e is a function call (7.6.1.3 [expr.call]) or an invocation of an overloaded operator (parentheses around e are ignored), decltype(e) is the return type of that function;

The reference to “that function” is imprecise; it is not the actual function called at runtime but the statically chosen function (ignoring covariant return types in virtual functions).

Also, the examples in this paragraph have errors:

  1. The declaration of struct A should end with a semicolon.

  2. The lines of the form decltype(...); are ill-formed; they need a declarator.

History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1819
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetstatus: review -> ready
2008-02-03 00:00:00adminsetmessages: + msg1579
2008-02-03 00:00:00adminsetstatus: drafting -> review
2007-10-09 00:00:00adminsetstatus: open -> drafting
2007-08-16 00:00:00admincreate