Bug 21835 - compilation of CRTP fails if the ABC is after template
Summary: compilation of CRTP fails if the ABC is after template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2005-05-31 08:40 UTC by maierkom
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0
Known to fail: 3.4.0 3.3.3 3.0.4 2.95.3 4.0.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description maierkom 2005-05-31 08:40:15 UTC
the compilation of a curious recuring template fails if the base class for the
instantiation of the curious recuring template pattern (CRTP) is defined after
the template but before its instantiation.

The following code demonstrates the problem. If uncommenting the outcommented
section and commenting out the latter appearance of the same code, it compiles
successfully.

#include <iostream>

using namespace std;

/*
struct Client
{
	void visit(const class A &a)
	{ cout << "Client::visit(const A &)" << endl; }
};

struct MYABC
{
	virtual void runVisitor(class Client &) const = 0;
};
*/

template <class Derived, class ABC>
struct Door : public ABC
{
	Door()
	: ABC()
	{ }

	void runVisitor(class Client &) const;
};

template <class Derived, class ABC>
void Door<Derived,ABC>::runVisitor(class Client &c) const
{ c.visit(static_cast<const Derived &>(*this)); }

struct Client
{
	void visit(const class A &a)
	{ cout << "Client::visit(const A &)" << endl; }
};

struct MYABC
{
	virtual void runVisitor(class Client &) const = 0;
};

struct A : public Door<A,MYABC>
{
};
Comment 1 Andrew Pinski 2005-06-19 14:32:47 UTC
Fixed on the mainline (for 4.1.0), since this is not a regression, I am closing as fixed.