Error message in C++: increment of read-only member `c::x'
Gerald Pfeifer
pfeifer@dbai.tuwien.ac.at
Thu Sep 17 12:48:00 GMT 1998
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++;
}
};
Note that the entire class is read-only, not just member x.
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));
Or, better yet, a message like ``increment of `c::x' in constant member
function `f' ''?
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