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++/22364] New: Problems with friend function injection and destructor


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.

-- 
           Summary: Problems with friend function injection and destructor
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: cxl at ntllib dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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