1616#include " OutputLanguageMode.h"
1717#include " PrimitiveTypeMapping.h"
1818#include " SwiftToClangInteropContext.h"
19+ #include " swift/AST/ASTContext.h"
1920#include " swift/AST/Decl.h"
2021#include " swift/AST/SwiftNameTranslation.h"
2122#include " swift/AST/Type.h"
2223#include " swift/ClangImporter/ClangImporter.h"
2324#include " swift/IRGen/IRABIDetailsProvider.h"
2425#include " swift/IRGen/Linking.h"
26+ #include " clang/Basic/Module.h"
2527#include " llvm/ADT/STLExtras.h"
2628#include " llvm/Support/raw_ostream.h"
2729
@@ -642,20 +644,28 @@ void ClangValueTypePrinter::printTypeGenericTraits(
642644 });
643645 }
644646
647+ bool objCxxOnly = false ;
648+ if (const auto *clangDecl = typeDecl->getClangDecl ()) {
649+ if (cxx_translation::isObjCxxOnly (clangDecl, typeDecl->getASTContext ()))
650+ objCxxOnly = true ;
651+ }
652+
645653 // FIXME: avoid popping out of the module's namespace here.
646654 os << " } // end namespace \n\n " ;
647655 os << " namespace swift SWIFT_PRIVATE_ATTR {\n " ;
648656 auto classDecl = dyn_cast<ClassDecl>(typeDecl);
649657 bool addPointer =
650658 typeDecl->isObjC () || (classDecl && classDecl->isForeignReferenceType ());
651659
660+ if (objCxxOnly)
661+ os << " #if defined(__OBJC__)\n " ;
652662 os << " #pragma clang diagnostic push\n " ;
653663 os << " #pragma clang diagnostic ignored \" -Wc++17-extensions\"\n " ;
654- if (typeDecl->hasClangNode ()) {
664+ if (const auto *clangDecl = typeDecl->getClangDecl ()) {
655665 // FIXME: share the code.
656666 os << " template<>\n " ;
657667 os << " inline const constexpr bool isUsableInGenericContext<" ;
658- printer.printClangTypeReference (typeDecl-> getClangDecl () );
668+ printer.printClangTypeReference (clangDecl );
659669 if (addPointer)
660670 os << " *" ;
661671 os << " > = true;\n " ;
@@ -665,8 +675,8 @@ void ClangValueTypePrinter::printTypeGenericTraits(
665675 os << " struct" ;
666676 declAndTypePrinter.printAvailability (os, typeDecl);
667677 os << " TypeMetadataTrait<" ;
668- if (typeDecl->hasClangNode ()) {
669- printer.printClangTypeReference (typeDecl-> getClangDecl () );
678+ if (const auto *clangDecl = typeDecl->getClangDecl ()) {
679+ printer.printClangTypeReference (clangDecl );
670680 if (addPointer)
671681 os << " *" ;
672682 } else {
@@ -746,6 +756,8 @@ void ClangValueTypePrinter::printTypeGenericTraits(
746756 }
747757 os << " } // namespace\n " ;
748758 os << " #pragma clang diagnostic pop\n " ;
759+ if (objCxxOnly)
760+ os << " #endif // #if defined(__OBJC__)\n " ;
749761 os << " } // namespace swift\n " ;
750762 os << " \n " ;
751763 printer.printModuleNamespaceStart (*moduleContext);
0 commit comments