From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23554 invoked by alias); 17 Jan 2003 14:46:07 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 23536 invoked by uid 71); 17 Jan 2003 14:46:05 -0000 Date: Fri, 17 Jan 2003 14:46:00 -0000 Message-ID: <20030117144605.23535.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Hill Stephen-STEHILL1 Subject: Re: c++/6507: auto type promotion of referee in reference member variable initialization Reply-To: Hill Stephen-STEHILL1 X-SW-Source: 2003-01/txt/msg01045.txt.bz2 List-Id: The following reply was made to PR c++/6507; it has been noted by GNATS. From: Hill Stephen-STEHILL1 To: Hill Stephen-STEHILL1 , "'gcc-gnats@gcc.gnu.org'" , "'gcc-prs@gcc.gnu.org'" , "'gcc-bugs@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 <> 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 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--