GCC Bugzilla – Bug 14865
[3.3 Regression] No instantiation of VTT at -O1
Last modified: 2005-04-30 13:37:13 UTC
Here is the test example that causes the problem. I tried to reduce it to its strict minimum: test.cpp: #include <string> class A { std::string mesg; }; class B : public virtual A {}; template <class Type> class C : public B {}; int main() { C<int> j; } By compiling it with g++ 3.3.1 (Mandrake 9.2): g++ -O1 -o test test.cpp Returns error: /tmp/ccwnGZD1.o(.text+0x23): In function `main': : undefined reference to `VTT for C<int>' collect2: ld a retourné 1 code d'état d'exécution It seems that it has some problem instanciating the template class C<int> automatically. Here are different tests that DO work (each test is independant): - replace "std::string mesg" by "int mesg" - manually instanciate template class by putting "template class C<int>;" just before the main declaration - Move the delaration of j outside of main (global definition) - Compile with no optimisation (-O0 for example) To clarify things I tested this under: gcc 3.3.1 by Mandrake 9.2 : Failed gcc 3.3.2 by Fedora : Failed gcc 3.3.3 home compiled (with no options) : Failed gcc 3.2.2 by RedHat 9 : Work I thus suspect that this problem appeared with gcc versions 3.3 . It may also be that gcc 3.3 is more strict on the code but I have found no indication to suport this. Clement Menier.
Confirmed in 3.3.3 (but note this is fixed in 3.4.0 already but it is a regression from 3.2.3 so keeping open still).
Here's a reduced example. It gives linker errors when compiled with -O since gcc 3.3. Alas even 3.4 branch and mainline fail. :-( ==================================================== struct A { virtual ~A() {} }; struct B : public virtual A {}; template <typename> struct C : public B {}; int main() { C<int> c; return 0; } ====================================================
Adding note that this fails at -O2 or above with -fno-unit-at-a-time.
Retargeting to 3.4.1, being a regression on that release branch.
Fixed on mainline by Andrew's patches to cp-tree.h: http://gcc.gnu.org/ml/gcc-cvs/2004-06/msg00050.html http://gcc.gnu.org/ml/gcc-cvs/2004-06/msg00055.html (the second patch fixes a typo in the first one). Since the respective lines in cp-tree.h are the same on the 3.3 and 3.4 branch a backport seems to be easy. Andrew, will you give it a try?
No because the patch is wrong in the first place and causes another regression which is even worse than this one, it causes QT to fail at build at -O0.
This was just broken again on the mainline by my patch to revert the patch which fixes it but the orginal patch was broken in the first place.
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01979.html>.
Jan, did this patch test out OK? If not, would some else care to test the patch? It is OK if it passes tests.
Subject: Re: [3.3/3.4/3.5 Regression] [no-unit-at-a-time] No instantiation of VTT at -O1 > > ------- Additional Comments From mmitchel at gcc dot gnu dot org 2004-06-25 21:37 ------- > Jan, did this patch test out OK? > > If not, would some else care to test the patch? It is OK if it passes tests. It passed for 3.4 and mainline, it didn't apply clearly to 3.3. I will update it for 3.3 and re-test and apply if passes after 30th. (I can access the net only once a day this week, so this caused the delay) Honza > > -- > What |Removed |Added > ---------------------------------------------------------------------------- > CC| |jh at suse dot cz > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14865 > > ------- You are receiving this mail because: ------- > You are on the CC list for the bug, or are watching someone who is.
Subject: Bug 14865 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: hubicka@gcc.gnu.org 2004-06-25 21:59:08 Modified files: gcc/cp : ChangeLog decl2.c Log message: PR C++/14865 * decl2.c (maybe_emit_vtables): Always import_export_vtable for the reachability analysis. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.127&r2=1.3892.2.128 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.695.4.8&r2=1.695.4.9
Subject: Bug 14865 CVSROOT: /cvs/gcc Module name: gcc Changes by: hubicka@gcc.gnu.org 2004-06-26 10:23:10 Modified files: gcc/cp : ChangeLog decl2.c Log message: PR C++/14865 * decl2.c (maybe_emit_vtables): Always import_export_vtable for the reachability analysis. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4130&r2=1.4131 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.720&r2=1.721
Adjust milestone
As per comment #10, there is no proposed patch for 3.3.6. Closing as won't fix..