[Bug c++/52185] New: Const member function may change the object for which the function is called.

2012-02-09 Thread lsoltysiak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52185

 Bug #: 52185
   Summary: Const member function may change the object for which
the function is called.
Classification: Unclassified
   Product: gcc
   Version: 4.7.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: lsoltys...@gmail.com


According to paper www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3242.pdf (
class.this point 2), a const member function shall not modify the object for
which the function is called.

With basic cases it is true, so for below class g++ returns error ('error:
increment of member ‘A::a’ in read-only object').

class A {
int a;
public: int fun() const { a++; }
};

Problems start when class contains references. In below example, const member
function allows to change internal state of class A instances. This shouldn't
be allowed. In my opinion compilation should failed, but g++ 4.7.0 doesn't
report any problem.

class A {
int   a1;
int  a2;
  public: 
A() : a2(a1) { }
int fun() const { a2++; }
};


[Bug c++/52185] Const member function may change the object for which the function is called.

2012-02-09 Thread lsoltysiak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52185

--- Comment #4 from xfg lsoltysiak at gmail dot com 2012-02-09 18:30:34 UTC 
---
Ok, I understood. Pointers are also quite good examples, to explain that. 

Thanks Jonathan.


[Bug c++/52174] New: Implicit conversion of nullptr to bool

2012-02-08 Thread lsoltysiak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52174

 Bug #: 52174
   Summary: Implicit conversion of nullptr to bool
Classification: Unclassified
   Product: gcc
   Version: 4.7.0
Status: UNCONFIRMED
  Severity: trivial
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: lsoltys...@gmail.com


Document 'A name for the null pointer: nullptr (revision 4)' states that
implicit conversion of nullptr to bool is not allowed. Unfortunately in g++
4.7.0, this requirement is not fulfilled. See example below.


if (nullptr) //shall return error, implicit conversion to bool not allowed