Topic: Defect Report [class.this]/2


Author: James Kanze<james.kanze@gmail.com>
Date: Mon, 25 Apr 2011 12:14:05 CST
Raw View
This is probably editorial, but it should be fixed.
[class.this]/9 states:

     In a const member function, the object for which the
     function is called is accessed through a const access
     path; therefore, a const member function shall not
     modify the object and its non-static data members.

This is clearly wrong: a const member function may modify the
object through another, non-const pointer, it may modify mutable
members, and it may cast away const, and modify anything in the
object.

The effects of const on the type of this are clearly stated in
the preceding paragraph; I would just drop this paragraph
(perhaps keeping the example, attaching it to the previous
paragraph, and adding more comment to the error case, along the
lines of "since 'a++' is 'this->a++', and 'this' has type 'const
s'").

--
James Kanze


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?=<daniel.kruegler@googlemail.com>
Date: Wed, 27 Apr 2011 10:55:21 CST
Raw View
On 2011-04-25 20:14, James Kanze wrote:
>
>  This is probably editorial, but it should be fixed.
>  [class.this]/9 states:
>
>        In a const member function, the object for which the
>        function is called is accessed through a const access
>        path; therefore, a const member function shall not
>        modify the object and its non-static data members.
>
>  This is clearly wrong: a const member function may modify the
>  object through another, non-const pointer, it may modify mutable
>  members, and it may cast away const, and modify anything in the
>  object.
>
>  The effects of const on the type of this are clearly stated in
>  the preceding paragraph; I would just drop this paragraph
>  (perhaps keeping the example, attaching it to the previous
>  paragraph, and adding more comment to the error case, along the
>  lines of "since 'a++' is 'this->a++', and 'this' has type 'const
>  s'").

Forwarded to core working group.

Greetings from Bremen,

Daniel Kr   gler


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]