Movatterモバイル変換


[0]ホーム

URL:


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

2025-11-05


452. Wording nit on description ofthis

Section:_N4868_.11.4.3.2  [class.this]    Status:CD1    Submitter:Gennaro Prota    Date:8 Jan 2004

[Voted into WP at July, 2007 meeting.]

_N4868_.11.4.3.2 [class.this] paragraph 1, which specifies themeaning of thekeyword 'this', seems to limit its usage to the *body* of non-staticmember functions. However 'this' is also usable in ctor-initializerswhich, according to the grammar in9.6 [dcl.fct.def] par. 1, are notpart of the body.

Proposed resolution: Changing the first part of_N4868_.11.4.3.2 [class.this] par. 1 to:

In the body of a nonstatic (9.3) member functionor in a ctor-initializer (12.6.2), the keywordthis is a non-lvalue expression whose value is the address of the object for which the function is called.

NOTE: I'm talking of constructors as functions that are "called";there have been discussions on c.l.c++.m as to whether constructorsare "functions" and to whether this terminology is correct or not; Ithink it is both intuitive and in agreement with the standard wording.

Steve Adamczyk: See alsoissue 397,which is defining a new syntax term for the body of a functionincluding the ctor-initializers.

Notes from the March 2004 meeting:

This will be resolved whenissue 397 is resolved.

Proposed resolution (October, 2005):

  1. Change 9.6 [dcl.fct.def] paragraph 1 as indicated:

  2. Function definitions have the form

    An informal reference to the body of a function should beinterpreted as a reference to the nonterminalfunction-body.

  3. Change the definition offunction-try-block inClause 14 [except] paragraph 1:

  4. Change 6.4.7 [basic.scope.class] paragraph 1, point 1, asindicated:

  5. The potential scope of a name declared in a class consists not only ofthe declarative region following the name's point of declaration, butalso of all functionbodies,bodies and defaultarguments, and constructorctor-initializers in thatclass (including such things in nested classes).
  6. Change 6.4.7 [basic.scope.class] paragraph 1, point 5, asindicated:

  7. The potential scope of a declaration that extends to or past the endof a class definition also extends to the regions defined by itsmember definitions, even if the members are defined lexically outsidethe class (this includes static data member definitions, nested classdefinitions, member function definitions (including the memberfunction bodyand, for constructor functions (11.4.5 [class.ctor]), the ctor-initializer (11.9.3 [class.base.init]))and any portion of the declarator part of such definitions whichfollows the identifier, including aparameter-declaration-clauseand any default arguments (9.3.4.7 [dcl.fct.default]).[Example:...
  8. Change footnote 32 in 6.5.3 [basic.lookup.unqual] paragraph 8as indicated:

  9. That is, an unqualified name that occurs, for instance, in a type ordefault argument expression in theparameter-declaration-clause,parameter-declaration-clause or in the function body,or in an expression of amem-initializer in a constructordefinition.
  10. Change _N4567_.5.1.1 [expr.prim.general] paragraph 3 as indicated:

  11. ...The keywordthis shall be used only inside a non-staticclass member function body (11.4.2 [class.mfct])or in aconstructormem-initializer (11.9.3 [class.base.init])...
  12. Change 11.4 [class.mem] paragraph 2 as indicated:

  13. ...Within the classmember-specification, the class is regarded ascomplete within function bodies, default arguments,andexception-specifications, and constructorctor-initializers (including such things in nested classes)...
  14. Change 11.4 [class.mem] paragraph 9 as indicated:

  15. Each occurrence in an expression of the name of a non-static datamember or non-static member function of a class shall be expressed asa class member access (7.6.1.5 [expr.ref]), except when itappears in the formation of a pointer to member (7.6.2.2 [expr.unary.op]), oror when it appears in the body ofa non-static member function of its class or of a class derived fromits class (11.4.3 [class.mfct.non.static]), or when it appears inamem-initializer for a constructor for its class or for aclass derived from its class (11.9.3 [class.base.init]).
  16. Change the note in 11.4.2 [class.mfct] paragraph 5 asindicated:

  17. [Note: a name used in a member function definition (that is, in theparameter-declaration-clause including the default arguments(9.3.4.7 [dcl.fct.default]), oror in the memberfunction body, or, for a constructor function (11.4.5 [class.ctor]), in amem-initializer expression (11.9.3 [class.base.init])) is looked up as described in 6.5 [basic.lookup]. —end note]
  18. Change 11.4.3 [class.mfct.non.static] paragraph 1 as indicated:

  19. ...A non-static member function may also be called directly usingthe function call syntax (7.6.1.3 [expr.call], 12.2.2.2 [over.match.call])from within the body of a member function of its class or of a class derived from its class.

  20. Change 11.4.3 [class.mfct.non.static] paragraph 3 as indicated:

  21. When anid-expression (_N4567_.5.1.1 [expr.prim.general]) that is notpart of a class member access syntax (7.6.1.5 [expr.ref])and not used to form a pointer to member (7.6.2.2 [expr.unary.op]) is used in the body of a non-static member functionof classXor used in themem-initializer for aconstructor of classX, if name lookup (6.5.3 [basic.lookup.unqual]) resolves the name in theid-expression to anon-static non-type member of classX or of a base classofX, theid-expression is transformed into a classmember access expression (7.6.1.5 [expr.ref])using(*this) (_N4868_.11.4.3.2 [class.this]) as thepostfix-expression to the left of the. operator...
  22. Change 11.4.5 [class.ctor] paragraph 7 as indicated:

  23. ...The implicitly-defined default constructor performs the set ofinitializations of the class that would be performed by a user-writtendefault constructor for that class withanemptymem-initializer-listnoctor-initializer (11.9.3 [class.base.init])and an emptyfunction bodycompound-statement...
  24. Change 11.9.3 [class.base.init] paragraph 4 as indicated:

  25. ...After the call to a constructor for classX has completed, if amember ofX is neither specified in the constructor'smem-initializers, nor default-initialized, norvalue-initialized, nor given a value during executionofthecompound-statement of the body of theconstructor, the member has indeterminate value.
  26. Change the last bullet of 11.9.3 [class.base.init] paragraph 5as indicated:

  27. Change Clause 14 [except] paragraph 4 as indicated:

  28. Afunction-try-block associates ahandler-seq with thector-initializer, if present, and thefunction-bodycompound-statement. An exception thrown during theexecution of the initializer expressions inthector-initializer or during the execution ofthefunction-bodycompound-statementtransfers control to a handler in afunction-try-block in the same way as an exception thrownduring the execution of atry-block transfers control to otherhandlers. [Example:

        int f(int);    class C {        int i;        double d;    public:        C(int, double);    };    C::C(int ii, double id)    try        : i(f(ii)), d(id)    {        // constructorfunction bodystatements    }    catch (...)    {        // handles exceptions thrown from the ctor-initializer        // and from the constructorfunction bodystatements    }

    end example]

  29. Change 14.3 [except.ctor] paragraph 2 as indicated:

  30. When an exception is thrown, control is transferred to the nearesthandler with a matching type (14.4 [except.handle]);“nearest” means the handler for which thecompound-statement,compound-statementorctor-initializer, orfunction-body followingthetry keyword was most recently entered by the thread ofcontrol and not yet exited.



[8]ページ先頭

©2009-2025 Movatter.jp