public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/10964] New: Problem with initialization of reference to pointer
@ 2003-05-24 11:17 lnxy2k@tiscali.de
2003-05-26 12:01 ` [Bug c++/10964] " ehrhardt@mathematik.uni-ulm.de
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: lnxy2k@tiscali.de @ 2003-05-24 11:17 UTC (permalink / raw)
To: gcc-bugs
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
Summary: Problem with initialization of reference to pointer
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: lnxy2k@tiscali.de
CC: gcc-bugs@gcc.gnu.org
Sytem: Linux (Debian 3.0 testing)
Problem: Wrong initialization of reference to pointer depends on declaration
sequence.
Try this:
#include <stdio.h>
class B1class
{
public:
void show_pointer() const
{ printf( "pointer in B1class is: %p\n", pntr ); }
protected:
B1class( const void * const p )
: pntr(p)
{}
private:
const void * const & pntr;
};
class B2class
{
public:
void show_pointer() const
{ printf( "pointer in B2class is: %p\n", pntr ); }
protected:
B2class( const void * const & p ) // In VARIANT_1 this causes trouble.
: pntr(p)
{}
private:
const void * const & pntr;
};
template< class T >
class Tclass
: public T
{
public:
Tclass()
: T(pointer),
pointer(0)
{}
void show_pointer() const
{
printf( "pointer in Tclass is: %p\n", pointer );
T::show_pointer();
}
void set_pointer( float *p ) { pointer = p; }
private:
float *pointer;
};
//#define VARIANT_2 1 // Uncomment this to see the difference
main()
{
#ifndef VARIANT_2
Tclass<B1class> T1;
Tclass<B2class> T2;
float number = 1.0;
#else
float number = 1.0;
Tclass<B1class> T1;
Tclass<B2class> T2;
#endif
T1.set_pointer( &number );
T1.show_pointer();
T2.set_pointer( &number );
T2.show_pointer();
}
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/10964] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
@ 2003-05-26 12:01 ` ehrhardt@mathematik.uni-ulm.de
2003-05-26 19:32 ` lnxy2k@tiscali.de
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ehrhardt@mathematik.uni-ulm.de @ 2003-05-26 12:01 UTC (permalink / raw)
To: gcc-bugs
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@mathematik.uni-ulm.de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
------- Additional Comments From ehrhardt@mathematik.uni-ulm.de 2003-05-26 11:07 -------
B1class.ptr is initialized by the constructor as a reference to the
parameter p of the constructor. This invokes undefined behaviour because
the life time of the reference exceeds that of the referenced storage
unit.
class B1class
{
B1class( const void * const p ) : pntr(p) {}
const void * const & pntr;
};
regards Christian
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/10964] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
2003-05-26 12:01 ` [Bug c++/10964] " ehrhardt@mathematik.uni-ulm.de
@ 2003-05-26 19:32 ` lnxy2k@tiscali.de
2003-06-02 4:16 ` [Bug target/10964] " pinskia@physics.uc.edu
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: lnxy2k@tiscali.de @ 2003-05-26 19:32 UTC (permalink / raw)
To: gcc-bugs
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
------- Additional Comments From lnxy2k@tiscali.de 2003-05-26 19:26 -------
Hi Cristian!
OK, you are right.
But please, look at the output of the example programm again.
At the first glance B1class seems to work, and B2class which is in my opinion
correct fails.
Furthermore, B1class should print an other value, i. e. the address
of the parameter p.
Sorry, I forgot to mention that my system is Linux (Debian 3.0 testing) on an
Intel P3.
Best regards Franz-Josef
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/10964] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
2003-05-26 12:01 ` [Bug c++/10964] " ehrhardt@mathematik.uni-ulm.de
2003-05-26 19:32 ` lnxy2k@tiscali.de
@ 2003-06-02 4:16 ` pinskia@physics.uc.edu
2003-06-02 6:07 ` lnxy2k@tiscali.de
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia@physics.uc.edu @ 2003-06-02 4:16 UTC (permalink / raw)
To: gcc-bugs
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
pinskia@physics.uc.edu changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
Component|c++ |target
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2003-06-02 04:16:53
date| |
------- Additional Comments From pinskia@physics.uc.edu 2003-06-02 04:16 -------
I can reproduce this problem on the mainline with -march=i386:
tin:~/src/gnu/gcctest>gcc -march=i386 pr10964.cc
tin:~/src/gnu/gcctest>./a.out
pointer in Mclass is: 0xbffec97c
pointer in Bclass is: 0xbffec9f4 <--- see this is different than above
tin:~/src/gnu/gcctest>gcc -march=i686 pr10964.cc
tin:~/src/gnu/gcctest>./a.out
pointer in Mclass is: 0xbffec97c
pointer in Bclass is: 0xbffec97c
Marking this as a target problem because it works on i686 and not i386.
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/10964] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
` (2 preceding siblings ...)
2003-06-02 4:16 ` [Bug target/10964] " pinskia@physics.uc.edu
@ 2003-06-02 6:07 ` lnxy2k@tiscali.de
2003-06-04 10:16 ` [Bug target/10964] [3.3/3.4 regression] [i?86] " giovannibajo@libero.it
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: lnxy2k@tiscali.de @ 2003-06-02 6:07 UTC (permalink / raw)
To: gcc-bugs
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
------- Additional Comments From lnxy2k@tiscali.de 2003-06-02 06:07 -------
Comment #7 seems to be OK. It is reproduceable on my box.
But if I try:
gcc-3.3 -march=i686 -O2 bug10964.cc
the problem returns again.
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/10964] [3.3/3.4 regression] [i?86] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
` (3 preceding siblings ...)
2003-06-02 6:07 ` lnxy2k@tiscali.de
@ 2003-06-04 10:16 ` giovannibajo@libero.it
2003-06-11 22:34 ` pinskia@physics.uc.edu
2003-06-27 12:56 ` ehrhardt at mathematik dot uni-ulm dot de
6 siblings, 0 replies; 8+ messages in thread
From: giovannibajo@libero.it @ 2003-06-04 10:16 UTC (permalink / raw)
To: gcc-bugs
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
giovannibajo@libero.it changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Last reconfirmed|2003-06-02 04:16:53 |2003-06-04 10:16:12
date| |
Summary|Problem with initialization |[3.3/3.4 regression] [i?86]
|of reference to pointer |Problem with initialization
| |of reference to pointer
------- Additional Comments From giovannibajo@libero.it 2003-06-04 10:16 -------
Confirmed on mainline and 3.3 branch (20030604). The bug can be reproduced with
either "-march=i386" or "-march=i686 -O2". It's a regression wrt 2.95.
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/10964] [3.3/3.4 regression] [i?86] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
` (4 preceding siblings ...)
2003-06-04 10:16 ` [Bug target/10964] [3.3/3.4 regression] [i?86] " giovannibajo@libero.it
@ 2003-06-11 22:34 ` pinskia@physics.uc.edu
2003-06-27 12:56 ` ehrhardt at mathematik dot uni-ulm dot de
6 siblings, 0 replies; 8+ messages in thread
From: pinskia@physics.uc.edu @ 2003-06-11 22:34 UTC (permalink / raw)
To: gcc-bugs
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
pinskia@physics.uc.edu changed:
What |Removed |Added
----------------------------------------------------------------------------
GCC build triplet| |i386-pc-linux-gnu
GCC host triplet| |i386-pc-linux-gnu
GCC target triplet| |i386-pc-linux-gnu
Target Milestone|3.4 |3.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/10964] [3.3/3.4 regression] [i?86] Problem with initialization of reference to pointer
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
` (5 preceding siblings ...)
2003-06-11 22:34 ` pinskia@physics.uc.edu
@ 2003-06-27 12:56 ` ehrhardt at mathematik dot uni-ulm dot de
6 siblings, 0 replies; 8+ messages in thread
From: ehrhardt at mathematik dot uni-ulm dot de @ 2003-06-27 12:56 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-06-27 12:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-24 11:17 [Bug c++/10964] New: Problem with initialization of reference to pointer lnxy2k@tiscali.de
2003-05-26 12:01 ` [Bug c++/10964] " ehrhardt@mathematik.uni-ulm.de
2003-05-26 19:32 ` lnxy2k@tiscali.de
2003-06-02 4:16 ` [Bug target/10964] " pinskia@physics.uc.edu
2003-06-02 6:07 ` lnxy2k@tiscali.de
2003-06-04 10:16 ` [Bug target/10964] [3.3/3.4 regression] [i?86] " giovannibajo@libero.it
2003-06-11 22:34 ` pinskia@physics.uc.edu
2003-06-27 12:56 ` ehrhardt at mathematik dot uni-ulm dot de
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).