[cfe-dev] Visiting Implicit Code [RecursiveASTVisitor]

Alexandros Tzannes atzannes at illinois.edu
Wed May 29 09:39:14 PDT 2013


Hi,
I'm writing a checker that needs to visit and understand implicit code 
(among other things).

Note: All three "should" functions of my visitor return true, though I'm 
not sure this matters in this specific case (keep reading).
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return true; }
   bool shouldWalkTypesOfTypeLocs() const { return true; }


In the code below the operator= is implicit (see commented out code)

class Data {
public:
   int x;
   int y;

//inline Data &operator=(const Data &D) noexcept {
//  this->x = D.x;
//  this->y = D.y;
//  return *this;
//}

};

void copy(Data in, Data out) {
   out = in;
}

I'm visiting the code using the RecursiveASTVisitor and my problem is 
that the parameter of the implicit function is not visited because 
getTypeSourceInfo() returns null on line 1739 of RecursiveASTVisitor.h

-- RecursiveASTVisitor.h:lines 1735-1741 ----------------------------

   // Visit the function type itself, which can be either
   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
   // also covers the return type and the function parameters,
   // including exception specifications.
   if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
   }

---------------------------------------------------------------------

Nevertheless, dumping the AST node for the CXXMethod (operator=) reveals 
that a nameless parameter is properly created.

Is this behavior (of not visiting the parameters of an implicit 
function) by design, or a corner case that slipped through the cracks? 
Any advice on how to visit the parameters of implicit functions with the 
RecursiveASTVisitor?

Cheers!
Alex



More information about the cfe-dev mailing list