[cfe-dev] Friend Declaration in clang

David Blaikie dblaikie at gmail.com
Mon Jan 21 09:37:15 PST 2013


On Mon, Jan 21, 2013 at 4:30 AM, madil90 <madil90 at gmail.com> wrote:
> 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.

> consider the following code as an example.
>
> class A
> {
> friend ostream &operator<<(ostream& out, A A1){}
> };
>
> Regards,
> Adil
>
>
>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/Friend-Declaration-in-clang-tp4029918.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list