Clang 3.0 variadic template pack expansion error

Hi,

I have been looking at some basic variadic template uses and so decided to give clang a go.

I downloaded the latest binaries from LLVM Download Page for Ubuntu 11.10 and have tried compiling the below code without success. The error returned is Error: too many template parameters in template redeclaration. I believe the syntax is correct. Can somebody confirm whether the error is a compiler bug or simply incorrect implementation.

#include <iostream>

template<typename ...ArgTypes>
class Tuple;

template<>
class Tuple<>
{
};

template<typename FirstType, typename ...RestTypes> // Too many template parameters
class Tuple : public Tuple<RestTypes...>
{
     private:
         FirstType Value;
     public:
         Tuple( FirstType ValueIn, RestTypes ...Others )
         :Tuple<RestTypes...>( Others ), Value( ValueIn )
         {
         }

         FirstType GetValue() const
         {
             return Value;
         }
};

int main( int argc, char **argv )
{
     Tuple<std::string> TestTuple( std::string( "Hello Tuple World!" ) );
     std::cout << TestTuple.GetValue() << std::endl;
     return 0;
}

clang -I /opt/clang/libcxx/include -I /media/Source/Generic -L /opt/clang/libcxx/lib hello_world.cpp -o hello_world -Wall -v -m64 -std=c++0x -stdlib=libc++ -ferror-limit=1

clang version 3.0 (tags/RELEASE_30/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Thanks

Nick

2)

Tuple( FirstType ValueIn, RestTypes ...Others )
:Tuple( Others... ), Value( ValueIn )

should be

Tuple( FirstType ValueIn, RestTypes ...Others )

:Tuple( Others ), Value( ValueIn )

note the "..." after "Others". A variadic parameter pack needs to be "expanded"
by writing "..." after it every time you mention it.

Sorry, I mixed that up. I meant:

Tuple( FirstType ValueIn, RestTypes ...Others )
:Tuple( Others ), Value( ValueIn )

should be

Tuple( FirstType ValueIn, RestTypes ...Others )
:Tuple( Others... ), Value( ValueIn )

Regards,
Nate

Your formatting got corrupted here; I assume you mean "class
Tuple<FirstType, RestTypes...> : public Tuple<RestTypes...>"

-Eli

>> 1)
>>
>> template // Too many template parameters
>> class Tuple : public Tuple
>>
>> should be
>>
>> template // Too many template parameters
>>
>> class Tuple : public Tuple
>>
>> since you want to declare a (partial) specialization of the primary template,
>> not the primary template itself.

Your formatting got corrupted here; I assume you mean "class
Tuple : public Tuple"

-Eli

Sorry about that, my mail client was in Rich Text mode and ate
the angle brackets (and what was between them) :frowning:

Let me try again:

template<typename FirstType, typename ...RestTypes>
class Tuple : public Tuple<RestTypes...>

should be

template<typename FirstType, typename ...RestTypes>
class Tuple<FirstType, RestTypes...> : public Tuple<RestTypes...>

and

:Tuple<RestTypes...>( Others ), Value( ValueIn )

should be

:Tuple<RestTypes...>( Others... ), Value( ValueIn )

Regards,
Nate