This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/6507: auto type promotion of referee in reference member variable initialization
- From: Hill Stephen-STEHILL1 <Stephen dot Hill at motorola dot com>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 17 Jan 2003 14:46:05 -0000
- Subject: Re: c++/6507: auto type promotion of referee in reference member variable initialization
- Reply-to: Hill Stephen-STEHILL1 <Stephen dot Hill at motorola dot com>
The following reply was made to PR c++/6507; it has been noted by GNATS.
From: Hill Stephen-STEHILL1 <Stephen.Hill@motorola.com>
To: Hill Stephen-STEHILL1 <Stephen.Hill@motorola.com>,
"'gcc-gnats@gcc.gnu.org'" <gcc-gnats@gcc.gnu.org>,
"'gcc-prs@gcc.gnu.org'" <gcc-prs@gcc.gnu.org>,
"'gcc-bugs@gcc.gnu.org'"
<gcc-bugs@gcc.gnu.org>,
"'nobody@gcc.gnu.org'" <nobody@gcc.gnu.org>
Cc:
Subject: Re: c++/6507: auto type promotion of referee in reference member
variable initialization
Date: Fri, 17 Jan 2003 14:41:56 -0000
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C2BE36.95877D52
Content-Type: text/plain;
charset="iso-8859-1"
Apologies,
I had some email issues which led to my mail of the testcase (attached)
being bounced. This got missed in the email deluge on my return from a
holiday. So here is the testcase again.
Thanks
Steve
<<bug_test.cc>>
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
r=6507
------_=_NextPart_000_01C2BE36.95877D52
Content-Type: application/octet-stream;
name="bug_test.cc"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="bug_test.cc"
/* gcc version 3.1 configured with configure --enable-threads =
--with-cpu=3Di686
first discovered on g++ version 2.95.2 19991024 (release)=20
=09
bug_test - steve hill 29/04/02. email: stephen.hill@motorola.com
=09
a,b are constant references to private member variables p_a,p_b. If we =
get the class wrong on p_b (line 52), then b and p_b are of different =
classes
but the compiler does not issue a warning or error, and makes p_b =
refer to a different address than the one we intend - probably because =
the automatic=20
type promotion is invoked. No warning is issued that auto type =
promotion (or whatever) has changed the address of the referee. */
#include <iostream>
using namespace std;
typedef unsigned short int ID;
class Foo
{
int i;
=09
public:
Foo(int j) //no bug if this is declared as explicit
:i(j)
{};
=09
/* //Issues a compile error if this is included because auto type =
promotion is not now possible
Foo()
:i(0)
{};=20
*/
~Foo()
{};
};
class bug_test
{
public:
const ID &a;
const Foo &b; =20
=09
bug_test()
:a(p_a),b(p_b),p_a(1),p_b(2)
{
cerr<<"Reference addresses:\t" << &a << " " << &b << "\n";
cerr<<"Referee addresses:\t"<<&p_a << " " << &p_b << "\n";
};
~bug_test()
{};
=09
private:
ID p_a;
ID p_b; // !! should be declared as a Foo !! =09
};
int main()
{
bug_test b;
return 0;
}
------_=_NextPart_000_01C2BE36.95877D52--