g++ 2.95.2 bug

Patrick J. Moran pmoran@nas.nasa.gov
Wed Feb 2 14:05:00 GMT 2000


Hello,

I have found what I think is a bug in the g++ 2.95.2 (release) compiler.
I do not see the bug listed in the current bug list.  The platform is
"Linux pc125 2.2.12-21smp #3 SMP Fri Nov 26 09:04:55 PST 1999 i686 unknown".
I have found a work-around, so this is not an urgent request.  The
work-around is insert the statement 'typedef T type;' in the primary
template.  I would think it should not matter, since only the specialization
gets instantiated in example, but it does.

Overall I have found the g++ compiler the best at handling templated
code, this is first problem that I have encountered with this compiler
version.  In any case, thanks for all your hard work.

Pat


pc125.pmoran 67> cat t6.C
template <class T> struct V { };
template <> struct V<int> { typedef int type; };

template <class T>
void fun()
{
  V<int>::type i;       // OK
  V<T>::type j;         // "parse error before `;'"
}

int main()
{
  fun<int>();
  return 0;
}


pc125.pmoran 69> g++ -v --save-temps t6.C -o t6
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Ac
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3
 /usr/local/include
 /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../i586-mandrake-linux/include
End of omitted list.
 /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/cc1plus t6.ii -quiet -dumpbase t6.cc -version -o t6.s
GNU C++ version 2.95.2 19991024 (release) (i586-mandrake-linux) compiled by GNU C version 2.95.2 19991024 (release).
t6.C: In function `void fun()':
t6.C:8: parse error before `;'
pc125.pmoran 70> 


pc125.pmoran 71> cat t6.ii
# 1 "t6.C"
template <class T> struct V { };
template <> struct V<int> { typedef int type; };

template <class T>
void fun()
{
  V<int>::type i;        
  V<T>::type j;          
}

int main()
{
  fun<int>();
  return 0;
}


pc125.pmoran 72> cat t6.s
        .file   "t6.C"
        .version        "01.01"
gcc2_compiled.:
.text
        .align 4
.globl main
        .type    main,@function
main:
.LFB1:
        pushl %ebp
.LCFI0:
        movl %esp,%ebp
.LCFI1:
        subl $8,%esp
.LCFI2:
        call fun__H1Zi_v_v
        xorl %eax,%eax
        jmp .L2
        xorl %eax,%eax
        jmp .L2
        .p2align 4,,7
.L2:
        movl %ebp,%esp
        popl %ebp
        ret
.LFE1:
.Lfe1:
        .size    main,.Lfe1-main
.section        .gnu.linkonce.t.fun__H1Zi_v_v,"ax",@progbits
        .align 4
        .weak   fun__H1Zi_v_v
        .type    fun__H1Zi_v_v,@function
fun__H1Zi_v_v:
.LFB2:
        pushl %ebp
.LCFI3:
        movl %esp,%ebp
.LCFI4:
        subl $24,%esp
.LCFI5:
        jmp .L4
        jmp .L3
        .p2align 4,,7
.L4:
.L3:
        movl %ebp,%esp
        popl %ebp
        ret
.LFE2:
.Lfe2:
        .size    fun__H1Zi_v_v,.Lfe2-fun__H1Zi_v_v

.section        .eh_frame,"aw",@progbits
__FRAME_BEGIN__:
        .4byte  .LLCIE1
.LSCIE1:
        .4byte  0x0
        .byte   0x1
        .byte   0x0
        .byte   0x1
        .byte   0x7c
        .byte   0x8
        .byte   0xc
        .byte   0x4
        .byte   0x4
        .byte   0x88
        .byte   0x1
        .align 4
.LECIE1:
        .set    .LLCIE1,.LECIE1-.LSCIE1
        .4byte  .LLFDE1
.LSFDE1:
        .4byte  .LSFDE1-__FRAME_BEGIN__
        .4byte  .LFB1
        .4byte  .LFE1-.LFB1
        .byte   0x4
        .4byte  .LCFI0-.LFB1
        .byte   0xe
        .byte   0x8
        .byte   0x85
        .byte   0x2
        .byte   0x4
        .4byte  .LCFI1-.LCFI0
        .byte   0xd
        .byte   0x5
        .align 4
.LEFDE1:
        .set    .LLFDE1,.LEFDE1-.LSFDE1
        .4byte  .LLFDE3
.LSFDE3:
        .4byte  .LSFDE3-__FRAME_BEGIN__
        .4byte  .LFB2
        .4byte  .LFE2-.LFB2
        .byte   0x4
        .4byte  .LCFI3-.LFB2
        .byte   0xe
        .byte   0x8
        .byte   0x85
        .byte   0x2
        .byte   0x4
        .4byte  .LCFI4-.LCFI3
        .byte   0xd
        .byte   0x5
        .align 4
.LEFDE3:
        .set    .LLFDE3,.LEFDE3-.LSFDE3
        .ident  "GCC: (GNU) 2.95.2 19991024 (release)"
pc125.pmoran 73> 

# -----------------------------------------------------------
# Patrick J. Moran            http://www.nas.nasa.gov/~pmoran
# MRJ Technology Solutions          NASA Ames Research Center


More information about the Gcc-bugs mailing list