This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3760: g++ rejects legal code
- To: nobody at gcc dot gnu dot org
- Subject: Re: c++/3760: g++ rejects legal code
- From: julian at OpenIT dot DE (Julian v. Bock)
- Date: 21 Jul 2001 19:26:00 -0000
- Cc: gcc-prs at gcc dot gnu dot org,
- Reply-To: julian at OpenIT dot DE (Julian v. Bock)
The following reply was made to PR c++/3760; it has been noted by GNATS.
From: julian@OpenIT.DE (Julian v. Bock)
To: "Uwe F. Mayer" <mayer@tux.org>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/3760: g++ rejects legal code
Date: 21 Jul 2001 21:22:42 +0200
Hi
>>>>> "Uwe" =3D=3D Uwe F Mayer <mayer@tux.org> writes:
Uwe> c++ rejects to compile a member function changing a mutable
Uwe> data member of a constant object instance. Direct changes of
Uwe> the mutable member (if public) are fine.
>> How-To-Repeat:
Uwe> Compile the program bug8.cc included below, and you will get
Uwe> the compile-time error message: $ g++ bug8.cc bug8.cc: In
Uwe> function `int main()': bug8.cc:19: passing `const class_m' as
Uwe> `this' argument of `void class_m::incr_i()' discards
Uwe> qualifiers
This is not a compiler bug.
The compiler complains because you are trying to call a non-const
member function of a const object. ("passing `const class_m' as `this'
argument of `void class_m::incr_i()' discards qualifiers").
Make class_m::incr_i a const member function and you are fine.
Julian
--=20
OpenIT GmbH Tel +49 211 239 577-0
Julian v. Bock Fax +49 211 239 577-10
Jahnstr. 18 julian@openit.de
40215 D=FCsseldorf http://www.openit.de