Bug 14865 - [3.3 Regression] No instantiation of VTT at -O1
: [3.3 Regression] No instantiation of VTT at -O1
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
: 3.3.1
: P2 normal
: 3.4.3
Assigned To: Not yet assigned to anyone
: http://gcc.gnu.org/ml/gcc-patches/200...
: monitored, patch, wrong-code
: 15816
:
  Show dependency treegraph
 
Reported: 2004-04-06 13:40 UTC by Clément Ménier
Modified: 2005-04-30 13:37 UTC (History)
5 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build:
Known to work: 3.2.3 3.4.1 4.0.0
Known to fail: 3.3 3.3.1 3.3.2 3.3.3 3.3.4 3.4.0
Last reconfirmed: 2005-02-26 18:42:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Clément Ménier 2004-04-06 13:40:50 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.
Comment 1 Andrew Pinski 2004-04-06 14:07:58 UTC
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).
Comment 2 Volker Reichelt 2004-04-15 14:24:24 UTC
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;
}
====================================================
Comment 3 Andrew Pinski 2004-05-03 05:03:06 UTC
Adding note that this fails at -O2 or above with -fno-unit-at-a-time.
Comment 4 Giovanni Bajo 2004-06-06 03:37:44 UTC
Retargeting to 3.4.1, being a regression on that release branch.
Comment 5 Volker Reichelt 2004-06-15 09:23:56 UTC
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?
Comment 6 Andrew Pinski 2004-06-15 13:44:22 UTC
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.
Comment 7 Andrew Pinski 2004-06-15 20:56:39 UTC
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.
Comment 8 Andrew Pinski 2004-06-24 21:16:23 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01979.html>.
Comment 9 Mark Mitchell 2004-06-25 21:37:25 UTC
Jan, did this patch test out OK?

If not, would some else care to test the patch?  It is OK if it passes tests.
Comment 10 Jan Hubicka 2004-06-25 21:55:54 UTC
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.
Comment 11 CVS Commits 2004-06-25 21:59:24 UTC
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

Comment 12 CVS Commits 2004-06-26 10:23:24 UTC
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

Comment 13 Gabriel Dos Reis 2004-09-28 13:30:15 UTC
Adjust milestone
Comment 14 Gabriel Dos Reis 2005-04-30 13:37:13 UTC
As per comment #10, there is no proposed patch for 3.3.6. Closing as
won't fix..