Error message in C++: increment of read-only member `c::x'
Gerald Pfeifer
pfeifer@dbai.tuwien.ac.at
Fri Nov 27 12:57:00 GMT 1998
On Thu, 17 Sep 1998, Gerald Pfeifer wrote:
> A colleague of mine got the error message
>
> foo.cc: In method `void c::f() const':
> foo.cc:5: increment of read-only member `c::x'
>
> which is quite misleading, IMHO, for the following (destilled) snippet:
>
> class c {
> int x,y,z;
> public:
> void f() const {
> x++;
> }
> };
A current snapshot diagnoses
foo.cc: In method `void c::f() const':
foo.cc:5: increment of member `c::x' in read-only structure
i.e., someone apparently has implemented my suggestion. Thanks!
> Wouldn't the first of these two messages in gcc/cp/typeck2.c be more
> intuitive?
>
> 96 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
> 99 fmt = "%s of member `%D' in read-only structure";
> 100 else
> 101 fmt = "%s of read-only member `%D'";
> 102 (*fn) (fmt, string, TREE_OPERAND (arg, 1));
Gerald
--
Gerald Pfeifer (Jerry) Vienna University of Technology
pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/
More information about the Gcc-bugs
mailing list