This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Error message in C++: increment of read-only member `c::x'


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/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]