Files
swift-mirror/test/Interop/Cxx/class/Inputs/friend-function.h
John Hui 75bcebe095 [cxx-interop] Do not add friend decls as members
Importing a friend constructor decl causes an assertion failure because
we eagerly add constructors as members, but the decl context of the
friend decl is different from the context we are adding it to.

That causes us to hit the following assertion:

    void IterableDeclContext::addMember(Decl *member, Decl *hint, bool insertAtHead) {
        ...
        assert(member->getDeclContext() == static_cast<DeclContext *>(nominal) &&
               "Added member to the wrong context");
        ...
    }

This patch continues to import friend decls (in case we rely on any side
effects from doing so) but bypasses any logic in VisitRecordDecl that
might cause a friend decl to be added as a member.

rdar://174353241
2026-04-14 15:07:18 -07:00

21 lines
374 B
C

#pragma once
struct A {
A();
void memberInA(int x) const;
};
struct B {
// These should not get imported as members of B, because friendship means
// nothing in Swift
friend A::A();
friend void A::memberInA(int) const;
void memberInB() const;
};
// C should not mistakenly "inherit" the friend declarations in B
struct C : B {
void memberInC() const;
};