I had problems (maybe mine) with template template and clang options. The following toy example compiles and runs under g ++ 4.7.0, rather than clang ++ 3.0 (based on LLVM 3.0), like ubuntu 12.04.
Toy example (test_1.cpp):
#include <iostream> #include <memory> struct AFn { void operator()() { ; // do something } }; template<typename T> struct impl { T *backpointer_; }; template<typename S, template <typename> class T> struct implT { T<S> *backpointer_; }; template<typename> class AClass; template<> struct implT<AFn, AClass> { implT(std::string message) : message_(message) {} void operator()() { std::cout << " : " << message_ << std::endl; } std::string message_; }; template<typename Fn> class AClass { private: std::shared_ptr<implT<Fn, AClass> > p_; public: AClass(std::string message) : p_(std::make_shared<implT<Fn, AClass> >(message)) {} void call_me() { p_->operator()(); } }; int main(int argc, char **argv) { AClass<AFn> *A = new AClass<AFn>("AClass<AFn>"); A->call_me(); delete A; return 0; }
clang output:
*****@ely:~$ clang++ -std=c++11 test_1.cpp -o test_1 test_1.cpp:47:30: error: template argument for template template parameter must be a class template or type alias template std::shared_ptr<implT<Fn, AClass> > p_; ^ test_1.cpp:47:40: error: C++ requires a type specifier for all declarations std::shared_ptr<implT<Fn, AClass> > p_; ^~ test_1.cpp:50:36: error: template argument for template template parameter must be a class template or type alias template p_(std::make_shared<implT<Fn, AClass> >(message)) ^ 3 errors generated. I can't make sense of the first error. It compiles and runs fine with gcc/g++ 4.7.0. Any help would be appreciated.
c ++ templates clang clang ++
Charles Pehlivanian
source share