16
16
#include " OutputLanguageMode.h"
17
17
#include " PrimitiveTypeMapping.h"
18
18
#include " SwiftToClangInteropContext.h"
19
+ #include " swift/AST/ASTContext.h"
19
20
#include " swift/AST/Decl.h"
20
21
#include " swift/AST/SwiftNameTranslation.h"
21
22
#include " swift/AST/Type.h"
22
23
#include " swift/ClangImporter/ClangImporter.h"
23
24
#include " swift/IRGen/IRABIDetailsProvider.h"
24
25
#include " swift/IRGen/Linking.h"
26
+ #include " clang/Basic/Module.h"
25
27
#include " llvm/ADT/STLExtras.h"
26
28
#include " llvm/Support/raw_ostream.h"
27
29
@@ -642,20 +644,28 @@ void ClangValueTypePrinter::printTypeGenericTraits(
642
644
});
643
645
}
644
646
647
+ bool objCxxOnly = false ;
648
+ if (const auto *clangDecl = typeDecl->getClangDecl ()) {
649
+ if (cxx_translation::isObjCxxOnly (clangDecl, typeDecl->getASTContext ()))
650
+ objCxxOnly = true ;
651
+ }
652
+
645
653
// FIXME: avoid popping out of the module's namespace here.
646
654
os << " } // end namespace \n\n " ;
647
655
os << " namespace swift SWIFT_PRIVATE_ATTR {\n " ;
648
656
auto classDecl = dyn_cast<ClassDecl>(typeDecl);
649
657
bool addPointer =
650
658
typeDecl->isObjC () || (classDecl && classDecl->isForeignReferenceType ());
651
659
660
+ if (objCxxOnly)
661
+ os << " #if defined(__OBJC__)\n " ;
652
662
os << " #pragma clang diagnostic push\n " ;
653
663
os << " #pragma clang diagnostic ignored \" -Wc++17-extensions\"\n " ;
654
- if (typeDecl->hasClangNode ()) {
664
+ if (const auto *clangDecl = typeDecl->getClangDecl ()) {
655
665
// FIXME: share the code.
656
666
os << " template<>\n " ;
657
667
os << " inline const constexpr bool isUsableInGenericContext<" ;
658
- printer.printClangTypeReference (typeDecl-> getClangDecl () );
668
+ printer.printClangTypeReference (clangDecl );
659
669
if (addPointer)
660
670
os << " *" ;
661
671
os << " > = true;\n " ;
@@ -665,8 +675,8 @@ void ClangValueTypePrinter::printTypeGenericTraits(
665
675
os << " struct" ;
666
676
declAndTypePrinter.printAvailability (os, typeDecl);
667
677
os << " TypeMetadataTrait<" ;
668
- if (typeDecl->hasClangNode ()) {
669
- printer.printClangTypeReference (typeDecl-> getClangDecl () );
678
+ if (const auto *clangDecl = typeDecl->getClangDecl ()) {
679
+ printer.printClangTypeReference (clangDecl );
670
680
if (addPointer)
671
681
os << " *" ;
672
682
} else {
@@ -746,6 +756,8 @@ void ClangValueTypePrinter::printTypeGenericTraits(
746
756
}
747
757
os << " } // namespace\n " ;
748
758
os << " #pragma clang diagnostic pop\n " ;
759
+ if (objCxxOnly)
760
+ os << " #endif // #if defined(__OBJC__)\n " ;
749
761
os << " } // namespace swift\n " ;
750
762
os << " \n " ;
751
763
printer.printModuleNamespaceStart (*moduleContext);
0 commit comments