Skip to content

Commit b93bfbe

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 b93bfbe

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
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++/ObjC++.
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
22+
23+
// 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
1924

2025
//--- header.h
2126

@@ -149,7 +154,7 @@ public func takeTrivialInout(_ x: inout Trivial) {
149154
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
150155
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
151156
// CHECK-NEXT:#endif
152-
// CHECK-NEXT: #pragma clang module import CxxTest;
157+
// CHECK-NEXT: #pragma clang module import CxxTest
153158
// CHECK-NEXT: #endif
154159

155160

0 commit comments

Comments
 (0)