Bug 10968 - [3.3/3.4 regression] If member function implicitly instantiated, explicit instantiation of class fails to instantiate it
Summary: [3.3/3.4 regression] If member function implicitly instantiated, explicit ins...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P1 critical
Target Milestone: 3.3.1
Assignee: Jason Merrill
URL:
Keywords:
: 11150 11652 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-24 14:04 UTC by jsberg04+bugs.gcc
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-06-02 06:08:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jsberg04+bugs.gcc 2003-05-24 14:04:18 UTC
$ gcc -v
Reading specs from /opt/gcc-3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs
Configured with: ../gcc-3.3/configure --prefix=/opt/gcc-3.3 --enable-threads
--with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.3

binutils 2.13.90.0.18
glibc 2.3.2

If a member function of a class is implicitly instantiated in a source file by
the member function of another class, and the class is subsequently explicitly
instantiated in the same source file, the member function that was implicitly
instantiated does not appear in the object file.  The problem doesn't occur if
the implicit instantiation was caused by a global function.

This behavior did not occur in 3.2.3.

Here are two files, test00.cc, test01.cc.  Compile as

$ c++ test00.cc test01.cc -o test01
/tmp/ccfV7tob.o(.text+0x17): In function `main':
: undefined reference to `A<int>::f() const'
collect2: ld returned 1 exit status

The object file for test00.cc contains the instantiation for char*,
but not int:

$ c++ -c test00.cc
$ nm -C -g test00.o
00000000 W A<char*>::f() const

# 1 "test00.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test00.cc"
# 1 "test00.hh" 1
template<class T> class A {
public:
  void f() const;
private:
};
# 2 "test00.cc" 2

template<class T> void A<T>::f() const { }

class C {
public:
  void f(const A<int> &a) const { a.f(); }
};

template class A<int>;
template class A<char *>;

# 1 "test01.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test01.cc"
# 1 "test00.hh" 1
template<class T> class A {
public:
  void f() const;
private:
};
# 2 "test01.cc" 2

int main(int argc, char *argv[]) {
  A<int> a;
  a.f();
}
Comment 1 Dara Hazeghi 2003-05-25 00:13:49 UTC
Hello,

I can confirm that this problem is not present on gcc 3.2, but is on gcc 3.3 branch and mainline 
(20030520). If this behavior is not correct, this is a regression from 3.2.

Dara
Comment 2 Giovanni Bajo 2003-05-29 14:41:50 UTC
A serious regression, if you ask me. I propose the following code snippet as
testcase to show the problem:

------------------------------------------------
template<class T> 
struct A
{
    void f(void)
    {}
};

struct Foo
{
    void bar(void)
    { 
        A<double> a;
        a.f(); 
    }
};

template class A<int>;
template class A<double>;
template class A<unsigned>;
template class A<char>;
------------------------------------------------

$ g++-3.3 -c pr10968.cpp && nm -C -g pr10968.o
00000000 T A<char>::f()
00000000 T A<int>::f()
00000000 T A<unsigned>::f()

$ g++-3.4 -c pr10968.cpp && nm -C -g pr10968.o
00000000 T A<char>::f()
00000000 T A<int>::f()
00000000 T A<unsigned>::f()

$ g++-3.2 -c pr10968.cpp && nm -C -g pr10968.o
00000000 T A<char>::f()
00000000 T A<double>::f()
00000000 T A<int>::f()
00000000 T A<unsigned>::f()


The instantiation of A<double> is missing only because it's referenced within 
Foo::bar().
Comment 3 CVS Commits 2003-06-10 19:06:23 UTC
Subject: Bug 10968

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	jason@gcc.gnu.org	2003-06-10 19:06:20

Modified files:
	gcc/cp         : pt.c 

Log message:
	PR c++/10968
	* pt.c (mark_decl_instantiated): Set TREE_SYMBOL_REFERENCED.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.27&r2=1.635.2.28

Comment 4 CVS Commits 2003-06-10 19:06:48 UTC
Subject: Bug 10968

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jason@gcc.gnu.org	2003-06-10 19:06:45

Modified files:
	gcc/cp         : ChangeLog 

Log message:
	PR c++/10968
	* pt.c (mark_decl_instantiated): Set TREE_SYMBOL_REFERENCED.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3409&r2=1.3410

Comment 5 CVS Commits 2003-06-10 19:07:22 UTC
Subject: Bug 10968

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jason@gcc.gnu.org	2003-06-10 19:07:20

Modified files:
	gcc/cp         : pt.c 

Log message:
	PR c++/10968
	* pt.c (mark_decl_instantiated): Set TREE_SYMBOL_REFERENCED.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.698&r2=1.699

Comment 6 CVS Commits 2003-06-10 19:08:00 UTC
Subject: Bug 10968

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	jason@gcc.gnu.org	2003-06-10 19:07:57

Modified files:
	gcc/cp         : ChangeLog 

Log message:
	PR c++/10968
	* pt.c (mark_decl_instantiated): Set TREE_SYMBOL_REFERENCED.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.143&r2=1.3076.2.144

Comment 7 CVS Commits 2003-06-10 19:08:50 UTC
Subject: Bug 10968

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jason@gcc.gnu.org	2003-06-10 19:08:46

Added files:
	gcc/testsuite/g++.dg/template: explicit-instantiation2.C 

Log message:
	PR c++/10968
	* pt.c (mark_decl_instantiated): Set TREE_SYMBOL_REFERENCED.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/explicit-instantiation2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 Jason Merrill 2003-06-10 19:25:49 UTC
Feexd.
Comment 9 Wolfgang Bangerth 2003-06-11 15:25:12 UTC
*** Bug 11150 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2003-07-23 22:41:49 UTC
*** Bug 11652 has been marked as a duplicate of this bug. ***