const/invariant bug?

Craig Black craigblack2 at cox.net
Wed Apr 2 23:43:26 PDT 2008


Unless I misunderstand something this shouldn't compile.  But it compiles 
fine in DMD 2.012.  Is this a bug?

import std.stdio;

class A
{
public:
  int x = 0;
  void setX(int nx) const { x = nx; }
}

void foo(const A a) { a.setX(1); }

int main(char[][] args)
{
  A a = new A;
  foo(a);
  writefln(a.x);
  return 0;
}




More information about the Digitalmars-d mailing list