This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/10964] [3.3/3.4 regression] [i?86] Problem with initialization of reference to pointer
- From: "ehrhardt at mathematik dot uni-ulm dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Jun 2003 12:56:38 -0000
- Subject: [Bug target/10964] [3.3/3.4 regression] [i?86] Problem with initialization of reference to pointer
- References: <20030524105816.10964.lnxy2k@tiscali.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10964
ehrhardt at mathematik dot uni-ulm dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
------- Additional Comments From ehrhardt at mathematik dot uni-ulm dot de 2003-06-27 12:56 -------
I think this is still not a bug! The problem is with the usage of const.
Here's a reduced version of the source code:
class Bclass
{
protected:
Bclass( const float * const & p ) {}
};
struct Mclass : public Bclass
{
Mclass() : Bclass(pointer), pointer (0) { } /* XXX */
float *pointer;
};
int main ()
{
Mclass M;
}
In the line marked with XXX pointer is of type ``float *''. However,
the Bclass constructor expects a ``const float * const'' reference.
These types are NOT reference compatible according to 8.5.3[4] because
of the additional const qualifier. This means according to 8.5.3[5]
that a temporary object is created from the expression ``pointer'' and
the reference in the Bclass constructor is bound to THAT temporary:
Otherwise, a temporary of type ``cv1 T1'' is created
and initialized from the initializer expression using
the rules for a non-reference copy initialization
(8.5). The reference is then bound to the tem-porary.
If T1 is reference-related to T2, cv1 must be the same
cv-qualification as, or greater cv-qualification than,
cv2; [ ... ]
Consequently the reference is to a temparary, not directly to the
element of Mclass. This explains the two different pointer values.
Due to life time issues (the life time of the reference exceeds that
of the temporary the program is also ill formed.
regards Christian