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]
Other format: [Raw text]

[Bug c++/11880] New: [regression] implicit template instantiation instantiate unused class methods


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11880

           Summary: [regression] implicit template instantiation instantiate
                    unused class methods
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: casteyde dot christian at free dot fr
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i585-linux-gnu
  GCC host triplet: i585-linux-gnu
GCC target triplet: i585-linux-gnu

Implicit instantiation should declare and instantiate only what is needed
at the instantiation point, as indicated in 14.7.1.1 [temp.inst] (draft 97).

GCC seems to instantiate the whole template at the instantiation point,
this can cause parse errors with forward class declaration used as
template parameters (see reproduce section).

This is a regression from GCC 3.2.3, which prevents OpenSP 1.5 from
compiling. Workaround : Suppress the forward declaration, or move the
point of instantiation after the full declaration of the template
parameter.

How to reproduce :
Compile the following minimal sample :

class Object
{
public:
	void destroy() {}
};

template <class T>
class ptr
{
	T *p;
public:
	ptr() : p(0) {}
	~ptr() { if (p) p->destroy(); }
};

class A;
class B : public Object
{
	ptr<A> a;
public:
	B() {}	// Should instantiate the template's data member
		// and ptr's constructor, but nothing requires
		// ptr's destructor instantiation.
		// However, gcc 3.3+ seems to requires full template
		// instantiation, therefore it complains that
		// the definition of A is missing.
		// See 14.7.1.1 [temp.inst].
};

class A : public Object
{
};

// If we inline B constructor here, there is no more problem:
//inline B::B() {}

int main(void)
{
	return 0;
}


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