Skip to content

Commit 651af99

Browse files
authored
Merge pull request #42428 from zoecarver/fix-use-def
2 parents 786d6ed + d2e3e0d commit 651af99

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,6 +3772,12 @@ namespace {
37723772
if (!Impl.SwiftContext.LangOpts.EnableCXXInterop)
37733773
return VisitRecordDecl(decl);
37743774

3775+
decl = decl->getDefinition();
3776+
if (!decl) {
3777+
forwardDeclaration = true;
3778+
return nullptr;
3779+
}
3780+
37753781
auto &clangSema = Impl.getClangSema();
37763782
// Make Clang define any implicit constructors it may need (copy,
37773783
// default). Make sure we only do this if the class has been fully defined
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_CXX_RECORD_USED_H
2+
#define TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_CXX_RECORD_USED_H
3+
4+
struct ForwardDeclaredInOtherHeader;
5+
6+
ForwardDeclaredInOtherHeader *usedInOtherHeader();
7+
8+
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_CXX_RECORD_USED_H
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_CXX_RECORD_H
2+
#define TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_CXX_RECORD_H
3+
4+
#include "forward-declared-cxx-record-used.h"
5+
6+
struct __attribute__((swift_attr("import_as_ref"))) ForwardDeclaredInOtherHeader {
7+
~ForwardDeclaredInOtherHeader() = delete;
8+
};
9+
10+
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_CXX_RECORD_H

test/Interop/Cxx/class/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,8 @@ module DictionaryOfNSStrings {
9797
header "dictionary-of-nsstrings.h"
9898
requires cplusplus
9999
}
100+
101+
module ForwardDeclaredCxxRecord {
102+
header "forward-declared-cxx-record.h"
103+
requires cplusplus
104+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=ForwardDeclaredCxxRecord -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2+
3+
// CHECK: func usedInOtherHeader() -> ForwardDeclaredInOtherHeader!
4+
// CHECK: class ForwardDeclaredInOtherHeader

0 commit comments

Comments
 (0)