gcc/testsuite/gdc.test/fail_compilation/fail223.d
raw| 1 | /* |
| 2 | TEST_OUTPUT: |
| 3 | --- |
| 4 | fail_compilation/fail223.d(14): Error: cannot modify `this.x` in `const` function |
| 5 | --- |
| 6 | */ |
| 7 | |
| 8 | //import std.stdio; |
| 9 | |
| 10 | class A |
| 11 | { |
| 12 | public: |
| 13 | int x = 0; |
| 14 | void setX(int nx) const { x = nx; } |
| 15 | } |
| 16 | |
| 17 | void foo(const A a) { a.setX(1); } |
| 18 | |
| 19 | int main(char[][] args) |
| 20 | { |
| 21 | A a = new A; |
| 22 | foo(a); |
| 23 | //writefln(a.x); |
| 24 | return 0; |
| 25 | } |