Topic: Defect report: usage of this outside function body


Author: technews@kangaroologic.com ("Jonathan Turkanis")
Date: Sat, 24 Jan 2004 02:00:50 +0000 (UTC)
Raw View
"Gennaro Prota" <gennaro_prota@yahoo.com> wrote in message
news:nekqvv0ipg1cjgbn2kmnbltanr31o5m9om@4ax.com...
>
> [Note: Forwarded to C++ Commitee -sdc ]
>
> 9.3.2 [class.this] paragraph 1, which specifies the meaning of the
> keyword 'this', seems to limit its usage to the *body* of non-static
> member functions. However 'this' is also usable in ctor-initializers
> which, according to the grammar in 8.4 [dcl.fct.def] par. 1, are not
> part of the body.

I assume you are aware of the following language from 12.6.2/7:

Names in the expression-list of a mem-initializer are evaluated in the
scope of the constructor for which the mem-initializer is specified.
<snip> [Note: because the mem-initializer are evaluated in the scope
of the constructor, the this pointer can be used in the
expression-list of a mem-initializer to refer to the object being
initialized. ]

>
> Proposed resolution: Changing the first part of 9.3.2 [class.this]
> par. 1 to:
>
>   "In the body of a nonstatic (9.3) member function or in a
>    ctor-initializer (12.6.2), the keyword this is a non-lvalue
>    expression whose value is the address of the object for which
>    the function is called."
>

I agree that the current wording of 9.3.2 is misleading. Might it not
be better to use the same language in both places, i.e., to modify
9.3.2 to refer to the scope of a constructor?

Jonathan


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Sat, 24 Jan 2004 18:56:25 +0000 (UTC)
Raw View
On Fri, 23 Jan 2004 17:30:57 +0000 (UTC), attila.feher@lmf.ericsson.se
("Attila Feher") wrote:

>Gennaro Prota wrote:
>[SNIP]
>> NOTE: I'm talking of constructors as functions that are "called";
>> there have been discussions on c.l.c++.m as to whether constructors
>> are "functions" and to whether this terminology is correct or not; I
>> think it is both intuitive and in agreement with the standard wording.
>
>IIRC the wording, constructors are called special member functions.

Only default and copy constructors :) Specifically I was remembering
this long discussion:

http://google.com/groups?threadm=3d236804.41282625%40news.earthlink.net

However my opinion is still the following

http://google.com/groups?selm=hri8iu05pkp1pgkp2k84oncl6ibuvn8818%404ax.com


Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Sat, 24 Jan 2004 19:10:36 +0000 (UTC)
Raw View
On Sat, 24 Jan 2004 02:00:50 +0000 (UTC), technews@kangaroologic.com
("Jonathan Turkanis") wrote:

>
>"Gennaro Prota" <gennaro_prota@yahoo.com> wrote
>>
>> Proposed resolution: Changing the first part of 9.3.2 [class.this]
>> par. 1 to:
>>
>>   "In the body of a nonstatic (9.3) member function or in a
>>    ctor-initializer (12.6.2), the keyword this is a non-lvalue
>>    expression whose value is the address of the object for which
>>    the function is called."
>>
>
>I agree that the current wording of 9.3.2 is misleading. Might it not
>be better to use the same language in both places, i.e., to modify
>9.3.2 to refer to the scope of a constructor?

Hmm. I'm under the impression that they purposely avoided talking of
scope in 9.3.2. The definition, there, is formulated in terms of
'body' and 'expression' rather than, respectively, 'scope' and
'name'/'identifier'. Maybe the underlying idea was that scope was
related to things that have a declaration, not keywords; I don't know.

But this is a minor defect anyway; both resolutions seem ok to me.

Just to elaborate a bit, I've often noticed such apparently careful
wordings in the standard that then get lost in other places. When you
read them in the first place you have the clear impression they are
trying to avoid some subtle logical pitfall, but then you go two
paragraphs on and... For instance I remember a "name" being defined as
the *use* of an identifier, not the identifier itself, but no other
part of the standard seems to stick to this distinction, and I'm not
fully conscious of what difference they actually tried to make. C'est
la vie... :)

That's probably due to the fact that different parts were written by
different people, in different moments. Also, definitions are almost
never given as real definitions but rather as colloquial description
of the meaning of a term.


Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: technews@kangaroologic.com ("Jonathan Turkanis")
Date: Sat, 24 Jan 2004 22:21:19 +0000 (UTC)
Raw View
"Gennaro Prota" <gennaro_prota@yahoo.com> wrote in message
news:up8510tcrvtomhqosq7d4ssv2t7g6hsnhb@4ax.com...
> On Sat, 24 Jan 2004 02:00:50 +0000 (UTC), technews@kangaroologic.com
> ("Jonathan Turkanis") wrote:
>
> >
> >"Gennaro Prota" <gennaro_prota@yahoo.com> wrote
> >>
> >> Proposed resolution: Changing the first part of 9.3.2
[class.this]
> >> par. 1 to:
> >>
> >>   "In the body of a nonstatic (9.3) member function or in a
> >>    ctor-initializer (12.6.2), the keyword this is a non-lvalue
> >>    expression whose value is the address of the object for which
> >>    the function is called."
> >>
> >
> >I agree that the current wording of 9.3.2 is misleading. Might it
not
> >be better to use the same language in both places, i.e., to modify
> >9.3.2 to refer to the scope of a constructor?
>
> Hmm. I'm under the impression that they purposely avoided talking of
> scope in 9.3.2. The definition, there, is formulated in terms of
> 'body' and 'expression' rather than, respectively, 'scope' and
> 'name'/'identifier'. Maybe the underlying idea was that scope was
> related to things that have a declaration, not keywords; I don't
know.

You may be right that discussion of scope was pusposely avoided here;
if so, my suggestion is inappropriate.

Other things being equal, I think it's best to use the same language
in both places; otherwise, people may spend a lot of time trying to
understand the distinction when none was intended, as you mention. (Or
worse, no one may remember whether a distinction was intended :-) )

Jonathan


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Tue, 20 Jan 2004 19:56:29 +0000 (UTC)
Raw View
[Note: Forwarded to C++ Commitee -sdc ]

9.3.2 [class.this] paragraph 1, which specifies the meaning of the
keyword 'this', seems to limit its usage to the *body* of non-static
member functions. However 'this' is also usable in ctor-initializers
which, according to the grammar in 8.4 [dcl.fct.def] par. 1, are not
part of the body.

Proposed resolution: Changing the first part of 9.3.2 [class.this]
par. 1 to:

  "In the body of a nonstatic (9.3) member function or in a
   ctor-initializer (12.6.2), the keyword this 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 constructors
are "functions" and to whether this terminology is correct or not; I
think it is both intuitive and in agreement with the standard wording.


Genny.



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: attila.feher@lmf.ericsson.se ("Attila Feher")
Date: Fri, 23 Jan 2004 17:30:57 +0000 (UTC)
Raw View
Gennaro Prota wrote:
[SNIP]
> NOTE: I'm talking of constructors as functions that are "called";
> there have been discussions on c.l.c++.m as to whether constructors
> are "functions" and to whether this terminology is correct or not; I
> think it is both intuitive and in agreement with the standard wording.

IIRC the wording, constructors are called special member functions.

--
Attila aka WW


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Fri, 23 Jan 2004 23:17:23 +0000 (UTC)
Raw View
9.3.2 [class.this] paragraph 1, which specifies the meaning of the
keyword 'this', seems to limit its usage to the *body* of non-static
member functions. However 'this' is also usable in ctor-initializers
which, according to the grammar in 8.4 [dcl.fct.def] par. 1, are not
part of the body.

Proposed resolution: Changing the first part of 9.3.2 [class.this]
par. 1 to:

  "In the body of a nonstatic (9.3) member function or in a
   ctor-initializer (12.6.2), the keyword this 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 constructors
are "functions" and to whether this terminology is correct or not; I
think it is both intuitive and in agreement with the standard wording.


Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]