public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/6507: auto type promotion of referee in reference member variable initialization
@ 2002-06-05  8:26 lerdsuwa
  0 siblings, 0 replies; 6+ messages in thread
From: lerdsuwa @ 2002-06-05  8:26 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, stephen.hill

Synopsis: auto type promotion of referee in reference member variable initialization

State-Changed-From-To: open->feedback
State-Changed-By: lerdsuwa
State-Changed-When: Wed Jun  5 08:26:53 2002
State-Changed-Why:
    The testcase is missing from the bug report.  Could you
    please submit it again?

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6507


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: c++/6507: auto type promotion of referee in reference member variable initialization
@ 2003-01-23  1:45 bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: bangerth @ 2003-01-23  1:45 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, stephen.hill

Synopsis: auto type promotion of referee in reference member variable initialization

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Thu Jan 23 01:45:36 2003
State-Changed-Why:
    Duplicate of PR 986.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6507


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: c++/6507: auto type promotion of referee in reference member variable initialization
@ 2003-01-17 14:47 paolo
  0 siblings, 0 replies; 6+ messages in thread
From: paolo @ 2003-01-17 14:47 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, stephen.hill

Synopsis: auto type promotion of referee in reference member variable initialization

State-Changed-From-To: closed->open
State-Changed-By: paolo
State-Changed-When: Fri Jan 17 06:47:39 2003
State-Changed-Why:
    At last, testcase received.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6507


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: c++/6507: auto type promotion of referee in reference member  variable initialization
@ 2003-01-17 14:46 Hill Stephen-STEHILL1
  0 siblings, 0 replies; 6+ messages in thread
From: Hill Stephen-STEHILL1 @ 2003-01-17 14:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

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--


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: c++/6507: auto type promotion of referee in reference member variable initialization
@ 2003-01-14 22:58 bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: bangerth @ 2003-01-14 22:58 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, stephen.hill

Synopsis: auto type promotion of referee in reference member variable initialization

State-Changed-From-To: feedback->closed
State-Changed-By: bangerth
State-Changed-When: Tue Jan 14 14:58:05 2003
State-Changed-Why:
    No feedback.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6507


^ permalink raw reply	[flat|nested] 6+ messages in thread

* c++/6507: auto type promotion of referee in reference member variable initialization
@ 2002-04-29  8:16 stephen.hill
  0 siblings, 0 replies; 6+ messages in thread
From: stephen.hill @ 2002-04-29  8:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6507
>Category:       c++
>Synopsis:       auto type promotion of referee in reference member variable initialization
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 29 08:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     stephen.hill@motorola.com
>Release:        gcc 2.95.2 19991024 (release)
>Organization:
>Environment:
Linux x86 (suse 7.0 default install)
>Description:
Note: I'm not sure if this really is a bug (or just a feature), but it strikes me that the code is doing something so different from a reasonable expectation that a closer examination of the reasoning might be desirable.

When initializing a reference member variable of a class, it appears that gcc attempts do do a type promotion of the referee into the reference class, then references the promoted variable.

In the attached code, note the difference between reference and referee addresses.If the constructor (lines 19-22) is replaced by a constructor which does not take an argument of the reference type (lines 24-27) an error is generated. This makes me believe that automatic type promotion is involved.

Note that if b (line 38) is declared as
   const explicit Foo &b;
rather than
   const Foo &b 
then no problem results.

Thanks,
steve
>How-To-Repeat:
compile attached file (gcc -o bug_test bug_test.cc)
run (./bug_test)
>Fix:
Assume that member references to member variables are explicit or warn?
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-01-23  1:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-05  8:26 c++/6507: auto type promotion of referee in reference member variable initialization lerdsuwa
  -- strict thread matches above, loose matches on Subject: below --
2003-01-23  1:45 bangerth
2003-01-17 14:47 paolo
2003-01-17 14:46 Hill Stephen-STEHILL1
2003-01-14 22:58 bangerth
2002-04-29  8:16 stephen.hill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).