How to tell if a NamedDecl is created by a FriendDecl?

In the following example, an “implicit” declaration of “class Y” will be created for “friend class Y” (it’s not marked as implicit in AST because it’s actually written in the friend declaration), and it will have the same USR as the real declaration. I couldn’t find a way to tell whether such decl was created by the friend decl when only given the NamedDecl. Checking its DeclContext doesn’t help because the context is the namespace nx.

  • namespace nx {
    class X {
    friend class Y;
    class Y {};
    } // namespace nx

I’m wondering if this is actually possible. If not, would it make sense to flag decls created by friend decls in the AST?


What about the lexical decl context?


Thanks Eric! That helps!

Use getFriendObjectKind()