Hi,
My goal is to find out whether every c++ class declaration in a file has
an overloaded "<<" stream operator. While traversing the AST, whenever I
encounter a CXXRecordDecl, I want to find out whether that recorddecl has an
overloaded operator with the spelling "<<". The problem is that the "<<"
operator is always declared as a friend method. When I traverse frienddecl,
I am unable to obtain a CXXMethodDecl from it (to check whether it's an
operator). Can you please tell me how can friend operators be detected?
consider the following code as an example.
class A
{
friend ostream &operator<<(ostream& out, A A1){}
};
Regards,
Adil
Hi,
My goal is to find out whether every c++ class declaration in a file has
an overloaded "<<" stream operator. While traversing the AST, whenever I
encounter a CXXRecordDecl, I want to find out whether that recorddecl has an
overloaded operator with the spelling "<<". The problem is that the "<<"
operator is always declared as a friend method. When I traverse frienddecl,
I am unable to obtain a CXXMethodDecl from it (to check whether it's an
operator). Can you please tell me how can friend operators be detected?
Have you tried using Clang's ast dumping (-dump-ast (or is it
-ast-dump? I always forget)) to see what the AST looks like so you
know what to write your program to search for? For one thing a friend
function like that is a free function, not a method.
This is not a CXXMethodDecl because it's not a declaration of a C++
method; it's a declaration of a namespace-scope function. You should
just check for a FunctionDecl.
John.