Skip to content

Commit db22b88

Browse files
authored
Merge pull request swiftlang#67976 from bnbarham/swap-cxx-include-order
[CxxInterop] Change C++ interop header ordering
2 parents f84724d + e0b976d commit db22b88

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

lib/PrintAsClang/ClangSyntaxPrinter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,15 @@ void ClangSyntaxPrinter::printPrimaryCxxTypeName(
388388

389389
void ClangSyntaxPrinter::printIncludeForShimHeader(StringRef headerName) {
390390
printIgnoredDiagnosticBlock("non-modular-include-in-framework-module", [&] {
391+
os << "// Allow user to find the header using additional include paths\n";
392+
os << "#if __has_include(<swiftToCxx/" << headerName << ">)\n";
393+
os << "#include <swiftToCxx/" << headerName << ">\n";
391394
os << "// Look for the C++ interop support header relative to clang's "
392395
"resource dir:\n";
393396
os << "// "
394397
"'<toolchain>/usr/lib/clang/<version>/include/../../../swift/"
395398
"swiftToCxx'.\n";
396-
os << "#if __has_include(<../../../swift/swiftToCxx/" << headerName
399+
os << "#elif __has_include(<../../../swift/swiftToCxx/" << headerName
397400
<< ">)\n";
398401
os << "#include <../../../swift/swiftToCxx/" << headerName << ">\n";
399402
os << "#elif __has_include(<../../../../../lib/swift/swiftToCxx/"
@@ -404,10 +407,6 @@ void ClangSyntaxPrinter::printIncludeForShimHeader(StringRef headerName) {
404407
"swift/swiftToCxx'.\n";
405408
os << "#include <../../../../../lib/swift/swiftToCxx/" << headerName
406409
<< ">\n";
407-
os << "// Alternatively, allow user to find the header using additional "
408-
"include path into '<toolchain>/lib/swift'.\n";
409-
os << "#elif __has_include(<swiftToCxx/" << headerName << ">)\n";
410-
os << "#include <swiftToCxx/" << headerName << ">\n";
411410
os << "#endif\n";
412411
});
413412
}

test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,19 @@
9494
// CHECK-EMPTY:
9595
// CHECK-NEXT: #endif
9696
// CHECK-NEXT: #define SWIFT_CXX_INTEROP_STRING_MIXIN
97+
9798
// CHECK-NEXT: #pragma clang diagnostic push
9899
// CHECK-NEXT: #pragma clang diagnostic ignored "-Wnon-modular-include-in-framework-module"
100+
// CHECK-NEXT: // Allow user to find the header using additional include paths
101+
// CHECK-NEXT: #if __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
102+
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
99103
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
100-
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
101-
// CHECK-NEXT: #if __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
104+
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
105+
// CHECK-NEXT: #elif __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
102106
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
103107
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
104-
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
108+
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
105109
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
106-
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
107-
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
108-
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
109110
// CHECK-NEXT: #endif
110111
// CHECK-NEXT: #pragma clang diagnostic pop
111112
// CHECK-NEXT: private:
@@ -129,14 +130,16 @@
129130

130131
// CHECK: #pragma clang diagnostic push
131132
// CHECK: #pragma clang diagnostic ignored "-Wnon-modular-include-in-framework-module"
132-
// CHECK: #if __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
133+
// CHECK-NEXT: // Allow user to find the header using additional include paths
134+
// CHECK-NEXT: #if __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
135+
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
136+
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
137+
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
138+
// CHECK-NEXT: #elif __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
133139
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
134140
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
135-
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
141+
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
136142
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
137-
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
138-
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
139-
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
140143
// CHECK-NEXT: #endif
141144
// CHECK-NEXTZ: #pragma clang diagnostic pop
142145

test/PrintAsCxx/empty.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@
9898
// CHECK-NEXT: #if defined(__cplusplus)
9999
// CHECK-NEXT: #pragma clang diagnostic push
100100
// CHECK-NEXT: #pragma clang diagnostic ignored "-Wnon-modular-include-in-framework-module"
101+
// CHECK-NEXT: // Allow user to find the header using additional include paths
102+
// CHECK-NEXT: #if __has_include(<swiftToCxx/_SwiftCxxInteroperability.h>)
103+
// CHECK-NEXT: #include <swiftToCxx/_SwiftCxxInteroperability.h>
101104
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
102-
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
103-
// CHECK-NEXT: #if __has_include(<../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>)
105+
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
106+
// CHECK-NEXT: #elif __has_include(<../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>)
104107
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>
105108
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>)
106-
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
109+
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
107110
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>
108-
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
109-
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftCxxInteroperability.h>)
110-
// CHECK-NEXT: #include <swiftToCxx/_SwiftCxxInteroperability.h>
111111
// CHECK-NEXT: #endif
112112
// CHECK-NEXT: #pragma clang diagnostic pop
113113
// CHECK-NEXT: #if __has_feature(objc_modules)

0 commit comments

Comments
 (0)