This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Error message in C++: increment of read-only member `c::x'
- To: egcs-bugs at cygnus dot com
- Subject: Error message in C++: increment of read-only member `c::x'
- From: Gerald Pfeifer <pfeifer at dbai dot tuwien dot ac dot at>
- Date: Thu, 17 Sep 1998 21:32:15 +0200 (MET DST)
- cc: Wolfgang Faber <faber at dbai dot tuwien dot ac dot at>
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/