@@ -68,11 +68,19 @@ template class LLVM_EXPORT_TEMPLATE basic_parser<float>;
68
68
template class LLVM_EXPORT_TEMPLATE basic_parser<std::string>;
69
69
template class LLVM_EXPORT_TEMPLATE basic_parser<char >;
70
70
71
- template class opt <unsigned >;
72
- template class opt <int >;
73
- template class opt <std::string>;
74
- template class opt <char >;
75
- template class opt <bool >;
71
+ #if !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) || \
72
+ !(defined(_MSC_VER) && !defined(__clang__))
73
+ // When DLL-exporting opt<std::string>, MSVC implicitly export std::basic_string
74
+ // because it is an ancestor. This situation leads to duplicate symbol errors at
75
+ // link time.
76
+ template class LLVM_EXPORT_TEMPLATE opt<std::string>;
77
+ #endif
78
+
79
+ template class LLVM_EXPORT_TEMPLATE opt<bool >;
80
+ template class LLVM_EXPORT_TEMPLATE opt<char >;
81
+ template class LLVM_EXPORT_TEMPLATE opt<int >;
82
+ template class LLVM_EXPORT_TEMPLATE opt<unsigned >;
83
+
76
84
} // namespace cl
77
85
} // namespace llvm
78
86
@@ -95,6 +103,16 @@ void parser<float>::anchor() {}
95
103
void parser<std::string>::anchor() {}
96
104
void parser<char >::anchor() {}
97
105
106
+ #if defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && defined(_MSC_VER) && \
107
+ !defined(__clang__)
108
+ // Force MSVC to export the vtable for the explicit opt instantiations above.
109
+ // Without these references, they may be optimized out at link time.
110
+ void opt_bool_anchor () { opt<bool > anchor{" " }; }
111
+ void opt_char_anchor () { opt<char > anchor{" " }; }
112
+ void opt_int_anchor () { opt<int > anchor{" " }; }
113
+ void opt_unsigned_anchor () { opt<unsigned > anchor{" " }; }
114
+ #endif
115
+
98
116
// ===----------------------------------------------------------------------===//
99
117
100
118
const static size_t DefaultPad = 2 ;
0 commit comments