Skip to content

Commit 228078f

Browse files
committed
[interop][SwiftToCxx] remove extraneous semicolon when emitting 'pragma clang module import'
The semicolon actually causes a compiler error in that case
1 parent 3bad906 commit 228078f

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

lib/PrintAsClang/PrintAsClang.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
448448
bool includeUnderlying = false;
449449
StringRef importDirective =
450450
useCxxImport ? "#pragma clang module import" : "@import";
451+
StringRef importDirectiveLineEnd = useCxxImport ? "\n" : ";\n";
451452
for (auto import : sortedImports) {
452453
if (auto *swiftModule = import.dyn_cast<ModuleDecl *>()) {
453454
if (useCxxImport) {
@@ -464,7 +465,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
464465
continue;
465466
}
466467
if (seenImports.insert(Name).second) {
467-
out << importDirective << ' ' << Name.str() << ";\n";
468+
out << importDirective << ' ' << Name.str() << importDirectiveLineEnd;
468469
if (frontendOpts.EmitClangHeaderWithNonModularIncludes) {
469470
if (const clang::Module *underlyingClangModule =
470471
swiftModule->findUnderlyingClangModule()) {
@@ -487,8 +488,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
487488
"top-level modules should use a normal swift::ModuleDecl");
488489
out << importDirective << ' ';
489490
ModuleDecl::ReverseFullNameIterator(clangModule).printForward(out);
490-
out << ";\n";
491-
491+
out << importDirectiveLineEnd;
492492
if (frontendOpts.EmitClangHeaderWithNonModularIncludes) {
493493
collectClangModuleHeaderIncludes(
494494
clangModule, fileManager, requiredTextualIncludes, visitedModules,

test/Interop/CxxToSwiftToCxx/bridge-cxx-struct-back-to-cxx.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
// RUN: %check-interop-cxx-header-in-clang(%t/full-cxx-swift-cxx-bridging.h -Wno-reserved-identifier)
1717

18-
// FIXME: test in C++ with modules (but libc++ modularization is preventing this)
18+
// Check that the generated header can be
19+
// built with Clang modules enabled in C++.
20+
21+
// RUN: %target-interop-build-clangxx -fsyntax-only -x c++-header %t/full-cxx-swift-cxx-bridging.h -std=gnu++20 -c -fmodules -fcxx-modules -I %t
1922

2023
//--- header.h
2124

@@ -149,7 +152,7 @@ public func takeTrivialInout(_ x: inout Trivial) {
149152
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
150153
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
151154
// CHECK-NEXT:#endif
152-
// CHECK-NEXT: #pragma clang module import CxxTest;
155+
// CHECK-NEXT: #pragma clang module import CxxTest
153156
// CHECK-NEXT: #endif
154157

155158

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %S/bridge-cxx-struct-back-to-cxx.swift %t
3+
4+
// RUN: %target-swift-frontend -typecheck %t/use-cxx-types.swift -typecheck -module-name UseCxxTy -emit-clang-header-path %t/UseCxxTy.h -I %t -enable-experimental-cxx-interop -clang-header-expose-decls=all-public -disable-availability-checking
5+
// RUN: echo "#include \"header.h\"" > %t/full-cxx-swift-cxx-bridging.h
6+
// RUN: cat %t/UseCxxTy.h >> %t/full-cxx-swift-cxx-bridging.h
7+
8+
// Check that the generated header can be
9+
// built with Clang modules enabled in ObjC++.
10+
11+
// REQUIRES: objc_interop
12+
13+
// RUN: %target-interop-build-clangxx -fsyntax-only -x objective-c++-header %t/full-cxx-swift-cxx-bridging.h -std=gnu++20 -c -fmodules -fcxx-modules -I %t

0 commit comments

Comments
 (0)