Skip to content

Commit 4fcaddb

Browse files
authored
Merge pull request #67726 from hyp/eng/friends-no-more
[cxx-interop] do not add friend decls as a member of Swift type that …
2 parents ae76f51 + f8dbc01 commit 4fcaddb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8937,6 +8937,11 @@ void ClangImporter::Implementation::loadAllMembersOfRecordDecl(
89378937
continue;
89388938
}
89398939

8940+
// A friend C++ decl is not a member of the Swift type.
8941+
if (member->getClangDecl() &&
8942+
member->getClangDecl()->getFriendObjectKind() != clang::Decl::FOK_None)
8943+
continue;
8944+
89408945
// FIXME: constructors are added eagerly, but shouldn't be
89418946
// FIXME: subscripts are added eagerly, but shouldn't be
89428947
if (!isa<AccessorDecl>(member) &&
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=Test -I %t/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
4+
5+
//--- Inputs/module.modulemap
6+
module Test {
7+
header "test.h"
8+
requires cplusplus
9+
}
10+
11+
//--- Inputs/test.h
12+
struct A {
13+
void memberInA(int x);
14+
};
15+
16+
struct B {
17+
friend void A::memberInA(int);
18+
19+
void memberInB();
20+
};
21+
22+
struct C: B {
23+
void memberInC();
24+
};
25+
26+
// CHECK: struct A {
27+
// CHECK: mutating func memberInA(_ x: Int32)
28+
// CHECK-NEXT: }
29+
// CHECK: struct B {
30+
// CHECK: mutating func memberInB()
31+
// CHECK-NEXT: }
32+
// CHECK: struct C {
33+
// CHECK: mutating func memberInC()
34+
// CHECK-NEXT: mutating func memberInB()
35+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)