Bug 22364 - Problems with friend function injection and destructor
Summary: Problems with friend function injection and destructor
Status: RESOLVED DUPLICATE of bug 22363
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-08 11:18 UTC by Mirek Fidler
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mirek Fidler 2005-07-08 11:18:23 UTC
This code does not compile:

template <class T>
struct Feature {
	friend void AssertFeature0(T *) {}
};

template <class T>
inline void AssertFeature(T *t = 0) { if(t) AssertFeature0(t); }

template <class T>
struct Test : Feature< Test<T> >
{
	int i;
	~Test() { AssertFeature<T>(); }
};

struct Foo : Feature<Foo> { int x; };

void foo()
{
	Test< Test<Foo> > test;
}

----------------------
The problem seems to be in fact that ~Test destructor is instantiated BEFORE
friend is injected and only in the case that templates are nested. Moving
AssertFeature to other method (and instatiating) or reducing test-case to just
"Test<Foo> test;" makes code compile fine.

Comeau C++ testdrive compiles this code without problems.
Comment 1 Wolfgang Bangerth 2005-07-08 14:19:32 UTC

*** This bug has been marked as a duplicate of 22363 ***