Movatterモバイル変換


[0]ホーム

URL:


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

2025-04-13


1207. Type of class member intrailing-return-type

Section:11.4.3  [class.mfct.non.static]    Status:C++11    Submitter:Jason Merrill    Date:2010-10-06

[Voted into the WP at the March, 2011 meeting as part of paper N3282.]

Consider the following example:

    struct vector {        struct iterator { };        struct const_iterator { };        iterator begin();        const_iterator begin() const;    };    class block {        vector v;        auto end() const -> decltype(v.begin()) { return v.begin(); }    };

Because the transformation of a member name into a class memberaccess expression (11.4.3 [class.mfct.non.static] paragraph 3) onlyoccurs inside the body of a non-static member function, the typeofv in thetrailing-return-type is non-const butis const in the return expression, resulting in a type mismatchbetween the return expression and the return type of the function.

One possibility would be to include thetrailing-return-typeas being subject to the transformation in 11.4.3 [class.mfct.non.static].Note, however, thatthis is currently not in scope at thatpoint (seeissue 945).

Notes from the November, 2010 meeting:

The CWG felt that, becausethis is effectively animplicit parameter, the best approach would be to model its usabilityon the visibility of parameters: it could be named wherever aparameter of the function is in scope.

Proposed resolution (February, 2011):

  1. Change _N4567_.5.1.1 [expr.prim.general] paragraph 2 as follows,adding three new paragraphs:

  2. The keywordthis names a pointer to the object for which anon-static member function (_N4868_.11.4.3.2 [class.this]) is invoked ora non-static data member's initializer (11.4 [class.mem]) isevaluated.The keywordthis shall be used only inside thebody of a non-static member function (11.4.2 [class.mfct]) of thenearest enclosing class or in abrace-or-equal-initializer fora non-static data member (11.4 [class.mem]). The type of theexpression is a pointer to the class of the function or non-staticdata member, possibly with cv-qualifiers on the class type. Theexpression is a prvalue.

    If afunction-definition ormember-declaratordeclares a member function of a classX, the expressionthis is a prvalue of type “pointer tocv-qualifier-seqX” between the optionalcv-qualifier-seq and the end of thefunction-definitionormember-declarator. It shall not appear before the optionalcv-qualifier-seq and it shall not appear within the declarationof a static member function (although its type and value category isdefined within a static member function as it is within a non-staticmember function). [Note: the type and value category is definedeven for the case of a static member function because declarationmatching does not occur until the complete declarator is known, andthis may be used in thetrailing-return-type of thedeclarator. —end note]

    Otherwise, if amember-declarator declares anon-static data member (11.4 [class.mem]) of a classX,the expressionthis is a prvalue of type “pointer toX” within the optionalbrace-or-equal-initializer.It shall not appear elsewhere in themember-declarator.

    The expressionthis shall not appear in any othercontext.

    [Example:...

  3. Change _N4567_.5.1.1 [expr.prim.general] paragraph 10 as follows:

  4. Anid-expression that denotes a non-static data member ornon-static member function of a class can only be used:

  5. Change 11.4.3 [class.mfct.non.static] paragraph 3 as follows:

  6. When anid-expression (7.5 [expr.prim]) that is notpart of a class member access syntax (7.6.1.5 [expr.ref]) andnot used to form a pointer to member (7.6.2.2 [expr.unary.op]) isused in thebodydeclaration of anon-static member function of classX, if namelookup (6.5 [basic.lookup]) resolves the name...



[8]ページ先頭

©2009-2025 Movatter.jp