This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
A bug in gcc 2.95, perhaps?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: A bug in gcc 2.95, perhaps?
- From: John Pierce <jlp at Cadence dot COM>
- Date: Thu, 28 Oct 1999 10:16:47 -0400
Hello,
I've been using gcc for about 8 years. This is the first bug that I've reported.
Keep up the good work! This is an excellent compiler.
What I have is the failure of 2.95 to apply a single argument constructor as
a type conversion when the class is a template. It works fine in 2.95 if the class
is not a template. With 2.7 I correctly get the application of the single argument constructor
of the template class. I realize that working in 2.7 and not working in 2.95 doesn't
necessarily indicate a bug. It could be related to 2.95 being more strick. But in this
case I think 2.95 is in error, or at least unnecessarily strict. Without type conversion by single
argument constructors the programmer is faced with having to code many permutations of
operatorX() member functions.
I created a small test case and include as follows all files - uncompressed since they aren't big.
You can see at the bottom of the .s file that this is version gcc 2.95.1.
I am running on Solaris 2.5.
<strike: 111> cat GCCBug.C
// forward declaration for template friend function
template<class T> class bug;
template<class T> const char operator==(const bug<T>&, const bug<T>&);
template<class T>
class bug
{
public:
inline bug() {};
bug(int);
inline ~bug() {};
#if (__GNUC__ == 2 && __GNUC_MINOR__ == 95)
friend const char operator==<>(const bug<T>&, const bug<T>&);
#else
friend const char operator==(const bug<T>&, const bug<T>&);
#endif
};
template<class T> bug<T>::bug(int a) {}
template<class T> const char operator==(const bug<T>&, const bug<T>&) { return 0; }
int main()
{
bug<int> a, b;
if (a == b) {}
if (a == 1) {} // GCC 2.95 gives: GCCBug.C:27: no match for `bug<int> & == int'
}
<strike:112> /usr/local/bin/gcc --save-temps GCCBug.C
GCCBug.C: In function `int main()':
GCCBug.C:27: no match for `bug<int> & == int'
<strike:113> cat GCCBug.ii
# 1 "GCCBug.C"
template<class T> class bug;
template<class T> const char operator==(const bug<T>&, const bug<T>&);
template<class T>
class bug
{
public:
inline bug() {};
bug(int);
inline ~bug() {};
friend const char operator==<>(const bug<T>&, const bug<T>&);
};
template<class T> bug<T>::bug(int a) {}
template<class T> const char operator==(const bug<T>&, const bug<T>&) { return 0; }
int main()
{
bug<int> a, b;
if (a == b) {}
if (a == 1) {}
}
<strike:114> cat GCCBug.s
.file "GCCBug.C"
gcc2_compiled.:
.global __throw
.section ".text"
.align 4
.global main
.type main,#function
.proc 04
main:
.LLFB1:
!#PROLOGUE# 0
save %sp, -120, %sp
.LLCFI0:
!#PROLOGUE# 1
add %fp, -17, %o1
mov %o1, %o0
call __t3bug1Zi, 0
nop
.LLEHB9:
add %fp, -18, %o1
mov %o1, %o0
call __t3bug1Zi, 0
nop
.LLEHB11:
add %fp, -17, %o0
add %fp, -18, %o1
call __eq__H1Zi_RCt3bug1ZX01T0_Cc, 0
nop
sll %o0, 24, %o1
sra %o1, 24, %o0
cmp %o0, 0
be .LL14
nop
.LL13:
.LL14:
.LLEHE11:
b .LL15
nop
.LL12:
call __throw, 0
nop
.LL15:
add %fp, -18, %o1
mov %o1, %o0
mov 2, %o1
call _._t3bug1Zi, 0
nop
.LLEHE9:
b .LL16
nop
.LL10:
call __throw, 0
nop
.LL16:
add %fp, -17, %o1
mov %o1, %o0
mov 2, %o1
call _._t3bug1Zi, 0
nop
mov 0, %i0
b .LL2
nop
b .LL17
nop
.LLEHB18:
.LL11:
add %fp, -18, %o1
mov %o1, %o0
mov 2, %o1
call _._t3bug1Zi, 0
nop
b .LL12
nop
.LL9:
add %fp, -17, %o1
mov %o1, %o0
mov 2, %o1
call _._t3bug1Zi, 0
nop
b .LL10
nop
.LLEHE18:
b .LL18
nop
.LL19:
call __throw, 0
nop
.LL20:
.LL18:
call terminate__Fv, 0
nop
.LL17:
.LL2:
ret
restore
.LLFE1:
.LLfe1:
.size main,.LLfe1-main
.section ".gnu.linkonce.t.__eq__H1Zi_RCt3bug1ZX01T0_Cc",#alloc,#execinstr
.align 4
.weak __eq__H1Zi_RCt3bug1ZX01T0_Cc
.type __eq__H1Zi_RCt3bug1ZX01T0_Cc,#function
.proc 04
__eq__H1Zi_RCt3bug1ZX01T0_Cc:
.LLFB2:
!#PROLOGUE# 0
save %sp, -112, %sp
.LLCFI1:
!#PROLOGUE# 1
st %i0, [%fp+68]
st %i1, [%fp+72]
mov 0, %i0
b .LL21
nop
.LL21:
ret
restore
.LLFE2:
.LLfe2:
.size __eq__H1Zi_RCt3bug1ZX01T0_Cc,.LLfe2-__eq__H1Zi_RCt3bug1ZX01T0_Cc
.section ".gnu.linkonce.t._._t3bug1Zi",#alloc,#execinstr
.align 4
.weak _._t3bug1Zi
.type _._t3bug1Zi,#function
.proc 020
_._t3bug1Zi:
.LLFB3:
!#PROLOGUE# 0
save %sp, -112, %sp
.LLCFI2:
!#PROLOGUE# 1
mov %i0, %l0
mov %i1, %l1
.LL4:
and %l1, 1, %o0
cmp %o0, 0
be .LL6
nop
mov %l0, %o0
call __builtin_delete, 0
nop
b .LL6
nop
.LL5:
.LL6:
.LL3:
ret
restore
.LLFE3:
.LLfe3:
.size _._t3bug1Zi,.LLfe3-_._t3bug1Zi
.section ".gnu.linkonce.t.__t3bug1Zi",#alloc,#execinstr
.align 4
.weak __t3bug1Zi
.type __t3bug1Zi,#function
.proc 0110
__t3bug1Zi:
.LLFB4:
!#PROLOGUE# 0
save %sp, -112, %sp
.LLCFI3:
!#PROLOGUE# 1
mov %i0, %o0
.LL8:
mov %o0, %i0
b .LL7
nop
.LL7:
ret
restore
.LLFE4:
.LLfe4:
.size __t3bug1Zi,.LLfe4-__t3bug1Zi
.section ".gcc_except_table",#alloc,#write
.align 4
__EXCEPTION_TABLE__:
.uaword .LLEHB9
.uaword .LLEHE9
.uaword .LL9
.uaword .LLEHB11
.uaword .LLEHE11
.uaword .LL11
.uaword .LLEHB18
.uaword .LLEHE18
.uaword .LL18
.LLRTH1:
.uaword -1
.uaword -1
.section ".eh_frame",#alloc,#write
__FRAME_BEGIN__:
.uaword .LLECIE1-.LLSCIE1
.LLSCIE1:
.uaword 0x0
.byte 0x1
.asciz "eh"
.uaword __EXCEPTION_TABLE__
.byte 0x1
.byte 0x7c
.byte 0x65
.byte 0xc
.byte 0xe
.byte 0x0
.byte 0x9
.byte 0x65
.byte 0xf
.align 4
.LLECIE1:
.uaword .LLEFDE1-.LLSFDE1
.LLSFDE1:
.uaword .LLSFDE1-__FRAME_BEGIN__
.uaword .LLFB1
.uaword .LLFE1-.LLFB1
.byte 0x4
.uaword .LLCFI0-.LLFB1
.byte 0xd
.byte 0x1e
.byte 0x2d
.byte 0x9
.byte 0x65
.byte 0x1f
.align 4
.LLEFDE1:
.uaword .LLEFDE3-.LLSFDE3
.LLSFDE3:
.uaword .LLSFDE3-__FRAME_BEGIN__
.uaword .LLFB2
.uaword .LLFE2-.LLFB2
.byte 0x4
.uaword .LLCFI1-.LLFB2
.byte 0xd
.byte 0x1e
.byte 0x2d
.byte 0x9
.byte 0x65
.byte 0x1f
.align 4
.LLEFDE3:
.uaword .LLEFDE5-.LLSFDE5
.LLSFDE5:
.uaword .LLSFDE5-__FRAME_BEGIN__
.uaword .LLFB3
.uaword .LLFE3-.LLFB3
.byte 0x4
.uaword .LLCFI2-.LLFB3
.byte 0xd
.byte 0x1e
.byte 0x2d
.byte 0x9
.byte 0x65
.byte 0x1f
.align 4
.LLEFDE5:
.uaword .LLEFDE7-.LLSFDE7
.LLSFDE7:
.uaword .LLSFDE7-__FRAME_BEGIN__
.uaword .LLFB4
.uaword .LLFE4-.LLFB4
.byte 0x4
.uaword .LLCFI3-.LLFB4
.byte 0xd
.byte 0x1e
.byte 0x2d
.byte 0x9
.byte 0x65
.byte 0x1f
.align 4
.LLEFDE7:
.ident "GCC: (GNU) 2.95.1 19990816 (release)"
<strike:115>
-----------------------------
John Pierce
Cadence Design Systems, Inc.
270 Billerica Road
Chelmsford, MA 01824
Phone: 978.446.6295
Fax: 978.262.6636
jlp@cadence.com