Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>NOTE FROM OP: <em>VC++ was buggy. VC++ 2015 accepts the code correctly.</em></p> <p>My original answer that the code that VC++ rejected is disallowed in the standard actually was wrong: It is allowed as Johannes Schaub pointed out: in 5.1 [expr.prim.general] paragraph 12 it is described where an <em>id-expression</em> denoting a non-static data member or a non-static member function can be used. In particular, the last bullet states:</p> <blockquote> <p>if that id-expression denotes a non-static data member and it appears in an unevaluated operand.</p> </blockquote> <p>The expression in <code>decltype(expr)</code> is an unevaluated operand. Furthermore, 9.3.1 [class.mfct.non-static] paragraph 3 explains the situation where <code>this</code> is implicitly added to an expression:</p> <blockquote> <p>When an id-expression (5.1) that is not part of a class member access syntax (5.2.5) and not used to form a pointer to member (5.3.1) is used in a member of class X in a context where this can be used (5.1.1), if name lookup (3.4) resolves the name in the id-expression to a non-static non-type member of some class C, and if either the id-expression is potentially evaluated or C is X or a base class of X, the id-expression is transformed into a class member access expression (5.2.5) using (*this) (9.3.2) as the postfix-expression to the left of the . operator.</p> </blockquote> <p>The context in question is not "potentially evaluated" and there is no based involved. Thus, <code>this</code> isn't added and doesn't have to be in scope. Taken together, this means that the declaration</p> <pre><code>decltype(fwd.rbegin()) begin() const; </code></pre> <p>should be legal. It seems that using</p> <pre><code>decltype(static_cast&lt;Reverser&lt;Fwd&gt; const*&gt;(0)-&gt;fwd.rbegin()) begin() const; </code></pre> <p>is a work-around in cases where the compiler isn't correctly implemented.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload