[cfe-dev] Assertion crashing when visiting clang AST.

Enea Zaffanella zaffanella at cs.unipr.it
Sat Mar 17 01:23:57 PDT 2012


In one of our AST visitors we are getting a clang assertion failure 
triggered by method

    AccessSpecifier Decl::getAccess() const

which calls the following helper function:

    void Decl::CheckAccessDeclContext() const

A reduced testcase (for our visitor) is the following:

template <typename T>
class Outer {

   template <typename U>
   friend class Outer; // No crash

   template <typename U>
   class Inner {
     template <typename W>
     friend class Inner; // Crash
   };

};

As written in the comments, a crash is obtained when querying 
getAccess() on the ClassTemplateDecl node included in the *second* 
friend declaration (Inner), but not for the first one (Outer).

As far as we can tell, an explanation for this difference is due to the 
DeclContext of these two ClassTemplateDecl nodes:
  - the first one has the translation unit as a DeclContext;
  - the second one has the CXXRecordDecl Outer as DeclContext.

If our guess above is correct, then the check coded in
   void Decl::CheckAccessDeclContext() const;
is probably stricter than necessary. Or is it instead the case that the 
DeclContext of friend declarations should have been set differently?

Enea.



More information about the cfe-dev mailing list