[cfe-dev] isDerivedFrom() on template classes

Benjamin Orgogozo benjamin.orgogozo at normalesup.org
Mon Sep 5 07:32:10 PDT 2011


Hello,

I'm trying to write a clang plugin which must check if a particular
class derives from a class A.

When I parse the A class, I store a pointer to the CXXRecordDecl and for
other classes B, I use B->isDerivedFrom(A). This works well for template
classes like:

template <class T>
class A {
  [...]
};

class B : public A<B> {
  [...]
};

Here I detect that B inherits from A.

I have a problem when the B class looks like:

template <class U>
class B : public A < B<U> > {
};


Here, I go through the following code in clang:

[CXXInheritance.cpp:178]
    // C++ [temp.dep]p3:
    //   In the definition of a class template or a member of a class template,
    //   if a base class of the class template depends on a template-parameter,
    //   the base class scope is not examined during unqualified name lookup 
    //   either at the point of definition of the class template or member or 
    //   during an instantiation of the class tem- plate or member.
    if (BaseType->isDependentType())
      continue;


So I don't detect that B inherits from A.

Do you know if there is a way to do detect that B inherits from A in
that case?


Thanks for you help,

-- 
 Benjamin Orgogozo



More information about the cfe-dev mailing list