Loki's tricky templates

Paolo Carlini pcarlini@unitus.it
Fri Apr 20 14:14:00 GMT 2001


Hi all,

in the last few days, also encouraged by "Gaby" Dos Reis, I tried to
compile Alexandrescu's Loki library (*) with current Gcc3.0 (Gcc3.1).
Having cleaned a fair amount of typos and trivial errors (e.g., many
missing "typename", a missing <typeninfo>... I can send a complete list
to the interested), I eventually got a segmentation fault for the
Visitor.h header (I will report about other problems in the next weeks)

I clarify, right at the beginning, that this *cannot* be a regression
from Gcc2.95.2, which in this case issues an ICE 980422, but I would
like to ask your advice to understand *if eventually* Gcc3.x should be
able to compile such kind of template structures or viceversa those are
not, strictly speaking, legal ANSI/ISO C++.

>From the Visitor.h (and therein included headers), I distilled the
following critical snippet:

------------

template <class AtomicType, template <class> class Unit>
class GenScatterHierarchy : public Unit<AtomicType>
{
};

template <class T, typename R>
class Visitor
{
public:
    typedef R ReturnType;
};

template <typename R>
struct VisitorBinder
{
    template <class T>
    struct Result : public Visitor<T, R>
    {
    };
};

template <typename R, class TList>
class CyclicVisitor
    : public GenScatterHierarchy<TList, VisitorBinder<R>::Result>
{
public:
    typedef R ReturnType;
};

class DocElement
{
public:
    CyclicVisitor<void, DocElement>::ReturnType fun() {}
};

------------

Before bothering the list, I cross-checked with 4 other compilers
(running under Linux and Windoze), and I must say that the results are
discordant: two, not very compliant indeed, reject the code, one well
respected compiles it, another not.

Opinions???

P.

(*) http://www.awl.com/cseng/titles/0-201-70431-5



More information about the Gcc mailing list