[cfe-dev] clang fails to build templated C++ code that other compilers can

Sean McBride sean at rogue-research.com
Tue Jul 27 08:25:18 PDT 2010


Hello,

We are trying to get VTK, an open source project, to build with clang
(trunk 109432).  It builds with many other compilers on many platforms. 
We have one problem down to the following:

#include <iostream>

class vtkArray 
{
public:
  void PrintSelf(std::ostream &os) { 
    std::cout << "vtkArray PrintSelf" << std::endl;
  }
};

template<class ThisT, class BaseT>
class vtkTypeTemplate : public BaseT
{
public:
  typedef BaseT Superclass;
};

template<typename T>
class vtkTypedArray : public vtkTypeTemplate<vtkTypedArray<T>, vtkArray>
{
public:
  void PrintSelf(std::ostream &os);
};

template<typename T>
void vtkTypedArray<T>::PrintSelf(std::ostream &os)
{
  this->vtkTypedArray<T>::Superclass::PrintSelf(os); // ERROR
}

int main (int argc, char const *argv[])
{
  vtkTypedArray<int> array;
  array.PrintSelf(std::cout);
  return 0;
}

Which gives:

test.cp:28:27: error: no member named 'Superclass' in 'vtkTypedArray<T>'
  this->vtkTypedArray<T>::Superclass::PrintSelf(os);
        ~~~~~~~~~~~~~~~~~~^

I'm not enough of a C++ expert to know if clang is in error or just more
strict in some way.  Any language lawyers here? :)

Thanks,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.cp
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100727/2c6cc419/attachment.ksh>


More information about the cfe-dev mailing list