This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: class ``implementation'' info not always generated...


I've revised the code I posted earlier to make it easier for people
to examine the extent of the bug in EGCS. I've added conditional
compilation so that various sections of code can be enabled or disabled
to explore matters.  It's definitely an interesting one.

The conditional complilation options are:

    NOPRAGMA		-- Remove #pragma declarations
    NOOTHERCONSTRUCTOR	-- Remove definition of one of Foo's constructors
    NOVIRTUAL		-- Don't use virtual methods
    NOTEMPLATES		-- Avoid use of templates
    DECLARETEMPLATES	-- Declare the template instances used

The code compiles correctly with the following switches:

    -DNOPRAGMA
    -O -fexternal-templates -DDECLARETEMPLATES
    -fexternal-templates -DNOOTHERCONSTRUCTOR -DDECLARETEMPLATES
    -fexternal-templates -DNOVIRTUAL -DDECLARETEMPLATES   
    -DNOTEMPLATES
    -frepo -DNOPRAGMA
    -fno-implicit-templates -DNOPRAGMA -DDECLARETEMPLATES
    -fexternal-templates -DNOPRAGMA -DDECLARETEMPLATES 
	(^--- warns that #pragma should have been used )
    -falt-external-templates -DNOPRAGMA -DDECLARETEMPLATES
	(^--- warns that #pragma should have been used )
    -DNOVIRTUAL
    	(^--- no warning, but questionable/unnecessary use of #pragma)
    -DNOOTHERCONSTRUCTOR
    	(^--- no warning, but questionable/unnecessary use of #pragma)
    -O
	(^--- no warning, but questionable/unnecessary use of #pragma)

... however, it breaks when compiled with:

    -fexternal-templates -DDECLARETEMPLATES
    -fno-implicit-templates -DDECLARETEMPLATES
    	(^--- questionable/unnecessary use of #pragma)
    -frepo
    	(^--- questionable/unnecessary use of #pragma)
    -O0
    	(^--- questionable/unnecessary use of #pragma)

Perhaps since both forms of ``-fexternal-templates'' are depreciated
and the ``#pragma'' forms are supposed go away soon, no one is going
to worry about this bug, but I would certainly be interested in
finding out why it happens and why some of the things above (like
-DNOOTHERCONSTRUCTOR and -DNOVIRTUAL) make the bug go away.

Enclosed is my revised source code, and more detailed output from
compiles using the above flags.

Regards,

    Melissa.

Enc.

--- thingy.h -----------------------------------------------------------
#ifndef THING_H_INCLUDED
#define THING_H_INCLUDED
#ifndef NOPRAGMA
#pragma interface
#endif

#ifdef NOTEMPLATES
typedef int Val;
#else
template <typename Val>
#endif
struct BarVirtualBase {
#ifndef NOVIRTUAL
  virtual void explode() = 0;
#endif
};

#ifdef NOTEMPLATES
struct Bar : public BarVirtualBase {
#else
template <typename Val>
struct Bar : public BarVirtualBase<Val> {
#endif
  Val value;
  Bar(Val v) : value(v) { };
  void explode () { }
};

#ifdef DECLARETEMPLATES
extern template class BarVirtualBase<int>;
extern template class Bar<int>;
#endif

#endif // THING_H_INCLUDED
--- thingy.cc-----------------------------------------------------------
#ifndef NOPRAGMA
#pragma implementation
#endif
#include "thingy.h"
#ifdef DECLARETEMPLATES
template class BarVirtualBase<int>;
template class Bar<int>;
#endif
--- buggy.cc -----------------------------------------------------------
#include "thingy.h"

struct Foo {
#ifdef NOTEMPLATES
  Bar tag;
#else
  Bar<int> tag;
#endif
  Foo();
  Foo(Foo* whatever);
};

#ifndef NOOTHERCONSTRUCTOR
inline Foo::Foo(Foo* whatever) : tag(0) {}
#endif
inline Foo::Foo() : tag(0) {}
    
main () {
  Foo start;
}
------------------------------------------------------------------------

Below is a transcript of a session to investigate what happens and
what doesn't with the various compilation options.

unix% g++ -v
Reading specs from /usr/local/egcs/lib/gcc-lib/m68k-next-nextstep3/egcs-2.91.55/specs
gcc version egcs-2.91.55 19980824 (gcc2 ss-980609 experimental)
unix% alias check 'set args = ( \!* ) ; g++ -Wall -Winline -W -Wmissing-declarations -Wredundant-decls -Wsynth -Wno-unused $args -c thingy.cc && echo thingy.o: && nm thingy.o && g++ -Wall -Winline -W -Wmissing-declarations -Wredundant-decls -Wsynth -Wno-unused $args -c buggy.cc && echo buggy.o: && nm buggy.o && g++ -Wall -o buggy thingy.o buggy.o && echo buggy.o and thingy.o link okay'

unix% check -DNOPRAGMA
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
0000013c D __GLOBAL_$F$main
0000001a t ___3Foo
0000013c d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000074 t ___t14BarVirtualBase1Zi
0000003e t ___t3Bar1Zii
000000d2 t ___tft14BarVirtualBase1Zi
00000098 t ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
0000010e s __vt$t14BarVirtualBase1Zi
000000fe s __vt$t3Bar1Zi
0000008c t _explode__t3Bar1Zi
00000000 T _main
buggy.o and thingy.o link okay

unix% check -O -fexternal-templates -DDECLARETEMPLATES
thingy.o:
000000c0 D __GLOBAL_$F$_vt$t3Bar1Zi
000000c0 d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000008 T ___t3Bar1Zii
0000005a T ___tft14BarVirtualBase1Zi
00000022 T ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
00000090 S __vt$t14BarVirtualBase1Zi
00000080 S __vt$t3Bar1Zi
00000000 T _explode__t3Bar1Zi
buggy.o:
00000018 D __GLOBAL_$F$main
00000018 d ___FRAME_BEGIN__
         U __vt$t3Bar1Zi
00000000 T _main
buggy.o and thingy.o link okay

unix% check -fexternal-templates -DNOOTHERCONSTRUCTOR -DDECLARETEMPLATES
thingy.o:
00000100 D __GLOBAL_$F$__t3Bar1Zii
00000100 d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000000 t ___t14BarVirtualBase1Zi
00000018 T ___t3Bar1Zii
00000094 T ___tft14BarVirtualBase1Zi
0000005a T ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
000000d0 S __vt$t14BarVirtualBase1Zi
000000c0 S __vt$t3Bar1Zi
0000004e T _explode__t3Bar1Zi
buggy.o:
00000040 D __GLOBAL_$F$main
0000001a t ___3Foo
00000040 d ___FRAME_BEGIN__
         U ___t3Bar1Zii
00000000 T _main
buggy.o and thingy.o link okay

unix% check -fexternal-templates -DNOVIRTUAL -DDECLARETEMPLATES
thingy.o:
00000028 D __GLOBAL_$F$__t3Bar1Zii
00000028 d ___FRAME_BEGIN__
00000000 T ___t3Bar1Zii
0000001a T _explode__t3Bar1Zi
buggy.o:
00000040 D __GLOBAL_$F$main
0000001a t ___3Foo
00000040 d ___FRAME_BEGIN__
         U ___t3Bar1Zii
00000000 T _main
buggy.o and thingy.o link okay

unix% check -DNOTEMPLATES
thingy.o:
000000f8 D __GLOBAL_$F$__3Bari
000000a8 t ___14BarVirtualBase
00000000 T ___3Bari
000000f8 d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
0000007c T ___tf14BarVirtualBase
00000042 T ___tf3Bar
00000008 C ___ti14BarVirtualBase
0000000c C ___ti3Bar
000000d0 S __vt$14BarVirtualBase
000000c0 S __vt$3Bar
00000036 T _explode__3Bar
buggy.o:
00000040 D __GLOBAL_$F$main
         U ___3Bari
0000001a t ___3Foo
00000040 d ___FRAME_BEGIN__
00000000 T _main
buggy.o and thingy.o link okay

unix% rm buggy.rpo
unix% check -frepo -DNOPRAGMA
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
0000008c D __GLOBAL_$F$main
0000001a t ___3Foo
0000008c d ___FRAME_BEGIN__
00000074 t ___t14BarVirtualBase1Zi
0000003e t ___t3Bar1Zii
         U __vt$t14BarVirtualBase1Zi
         U __vt$t3Bar1Zi
00000000 T _main
collect: recompiling buggy.cc
collect: relinking
buggy.o and thingy.o link okay
unix% nm buggy.o
0000013c D __GLOBAL_$F$main
00000026 t ___3Foo
0000013c d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
000000e6 t ___t14BarVirtualBase1Zi
0000004a t ___t3Bar1Zii
000000ba T ___tft14BarVirtualBase1Zi
00000080 T ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
0000010e S __vt$t14BarVirtualBase1Zi
000000fe S __vt$t3Bar1Zi
0000001a t _explode__t3Bar1Zi
00000000 T _main

unix% check -fno-implicit-templates -DNOPRAGMA -DDECLARETEMPLATES
thingy.o:
00000100 D __GLOBAL_$F$__t3Bar1Zii
00000100 d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000000 t ___t14BarVirtualBase1Zi
00000018 T ___t3Bar1Zii
00000094 T ___tft14BarVirtualBase1Zi
0000005a T ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
000000d0 S __vt$t14BarVirtualBase1Zi
000000c0 S __vt$t3Bar1Zi
0000004e T _explode__t3Bar1Zi
buggy.o:
00000040 D __GLOBAL_$F$main
0000001a t ___3Foo
00000040 d ___FRAME_BEGIN__
         U ___t3Bar1Zii
00000000 T _main
buggy.o and thingy.o link okay

unix% check -fexternal-templates -DNOPRAGMA -DDECLARETEMPLATES
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
thingy.h: In instantiation of `Bar<int>::Bar<int>(int)':
buggy.cc:14:   instantiated from here
thingy.h:25: warning: template `Bar<Val>::Bar(Val)' defined in file without #pragma interface
buggy.o:
0000013c D __GLOBAL_$F$main
0000001a t ___3Foo
0000013c d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000074 t ___t14BarVirtualBase1Zi
0000003e t ___t3Bar1Zii
000000d2 t ___tft14BarVirtualBase1Zi
00000098 t ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
0000010e s __vt$t14BarVirtualBase1Zi
000000fe s __vt$t3Bar1Zi
0000008c t _explode__t3Bar1Zi
00000000 T _main
buggy.o and thingy.o link okay

unix% check -falt-external-templates -DNOPRAGMA -DDECLARETEMPLATES
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.cc: In instantiation of `Bar<int>::Bar<int>(int)':
buggy.cc:14:   instantiated from here
buggy.cc:14: warning: template `Bar<int>::Bar<int>(int)' instantiated in file without #pragma interface
buggy.o:
0000013c D __GLOBAL_$F$main
0000001a t ___3Foo
0000013c d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000074 t ___t14BarVirtualBase1Zi
0000003e t ___t3Bar1Zii
000000d2 t ___tft14BarVirtualBase1Zi
00000098 t ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
0000010e s __vt$t14BarVirtualBase1Zi
000000fe s __vt$t3Bar1Zi
0000008c t _explode__t3Bar1Zi
00000000 T _main
buggy.o and thingy.o link okay

unix% check -DNOVIRTUAL
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
00000058 D __GLOBAL_$F$main
0000001a t ___3Foo
00000058 d ___FRAME_BEGIN__
0000003e t ___t3Bar1Zii
00000000 T _main
buggy.o and thingy.o link okay

unix% check -DNOOTHERCONSTRUCTOR
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
0000013c D __GLOBAL_$F$main
0000001a t ___3Foo
0000013c d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000074 t ___t14BarVirtualBase1Zi
0000003e t ___t3Bar1Zii
000000d2 t ___tft14BarVirtualBase1Zi
00000098 t ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
0000010e s __vt$t14BarVirtualBase1Zi
000000fe s __vt$t3Bar1Zi
0000008c t _explode__t3Bar1Zi
00000000 T _main
buggy.o and thingy.o link okay

unix% check -O
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
000000ac D __GLOBAL_$F$main
000000ac d ___FRAME_BEGIN__
         U ___rtti_si
         U ___rtti_user
00000056 t ___tft14BarVirtualBase1Zi
0000001e t ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
0000007c s __vt$t3Bar1Zi
00000016 t _explode__t3Bar1Zi
00000000 T _main
buggy.o and thingy.o link okay

unix% check -fexternal-templates -DDECLARETEMPLATES
thingy.o:
00000100 D __GLOBAL_$F$__t3Bar1Zii
00000100 d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000000 t ___t14BarVirtualBase1Zi
00000018 T ___t3Bar1Zii
00000094 T ___tft14BarVirtualBase1Zi
0000005a T ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
000000d0 S __vt$t14BarVirtualBase1Zi
000000c0 S __vt$t3Bar1Zi
0000004e T _explode__t3Bar1Zi
buggy.o:
0000001c D __GLOBAL_$F$main
         U ___3Foo
0000001c d ___FRAME_BEGIN__
00000000 T _main
/bin/ld: Undefined symbols:
Foo::Foo(void)
collect2: ld returned 1 exit status

unix% check -fno-implicit-templates -DDECLARETEMPLATES
thingy.o:
00000100 D __GLOBAL_$F$__t3Bar1Zii
00000100 d ___FRAME_BEGIN__
         U ___pure_virtual
         U ___rtti_si
         U ___rtti_user
00000000 t ___t14BarVirtualBase1Zi
00000018 T ___t3Bar1Zii
00000094 T ___tft14BarVirtualBase1Zi
0000005a T ___tft3Bar1Zi
00000008 C ___tit14BarVirtualBase1Zi
0000000c C ___tit3Bar1Zi
000000d0 S __vt$t14BarVirtualBase1Zi
000000c0 S __vt$t3Bar1Zi
0000004e T _explode__t3Bar1Zi
buggy.o:
0000001c D __GLOBAL_$F$main
         U ___3Foo
0000001c d ___FRAME_BEGIN__
00000000 T _main
/bin/ld: Undefined symbols:
Foo::Foo(void)
collect2: ld returned 1 exit status

unix% rm -f buggy.rpo 
unix% check -frepo  
check: Command not found.
unix% check -frepo
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
0000001c D __GLOBAL_$F$main
         U ___3Foo
0000001c d ___FRAME_BEGIN__
00000000 T _main
/bin/ld: Undefined symbols:
Foo::Foo(void)
collect2: ld returned 1 exit status

unix% check -O0
thingy.o:
00000000 D __GLOBAL_$F$thingy.cc
00000000 d ___FRAME_BEGIN__
buggy.o:
0000001c D __GLOBAL_$F$main
         U ___3Foo
0000001c d ___FRAME_BEGIN__
00000000 T _main
/bin/ld: Undefined symbols:
Foo::Foo(void)
collect2: ld returned 1 exit status


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]