[cfe-dev] A different behaviour of my matcher

Pedro Delgado Perez pedro.delgadoperez at mail.uca.es
Tue Oct 1 02:27:16 PDT 2013


 
Hi,

I built a matcher to retrieve a copy constructor with the form:

X(const X& copy) { ...}

DeclarationMatcher CC =
methodDecl(
               isCopyAssignmentOperator(), has(compoundStmt(has(stmt()))),
                   ofClass(recordDecl(hasCopyAssignmentWithConstParam()))      
         ).bind("CC");

Everything seemed to work fine, but something strange has happened today. I was testing the matcher with a program containing the next class in the header file:

class StrPair 
{ 
public: 
    
   StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} 
   ~StrPair(); 
 
   void Set( char* start, char* end, int flags ) { 
       Reset(); 
       _start = start; 
       _end   = end; 
       _flags = flags; 
   } 
 
   const char* GetStr(); 
 
   bool Empty() const { 
       return _start == _end; 
   } 
 
   void SetInternedStr( const char* str ) { 
       Reset(); 
       _start = const_cast<char*>(str); 
   } 
 
   void SetStr( const char* str, int flags=0 ); 
 
   char* ParseText( char* in, const char* endTag, int strFlags ); 
   char* ParseName( char* in ); 
 
private: 
   void Reset(); 
   void CollapseWhitespace(); 
 
   // After parsing, if *_end != 0, it can be set to zero. 
   int    _flags; 
   char*  _start; 
   char*  _end; 
};


To my surprise, my matcher retrieved the name of the class:

class StrPair
{
...

This program has a .cpp file defining some of the methods of the class as well, but only the header file is changed, so I think the .cpp file is not the problem.

However, to test what was happening, I put the class in another file with some other classes and the same matcher didn't make the change that I comment above.

What can be happening here? The class StrPair doesn't even have a copy constructor...

Thanks,

Pedro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131001/f7c53cf7/attachment.html>


More information about the cfe-dev mailing list