@@ -53,13 +53,7 @@ namespace llvm {
5353 Registry () = delete ;
5454
5555 friend class node ;
56- // These must be must two separate declarations to workaround a 20 year
57- // old MSVC bug with dllexport and multiple static fields in the same
58- // declaration causing error C2487 "member of dll interface class may not
59- // be declared with dll interface".
60- // https://developercommunity.visualstudio.com/t/c2487-in-dllexport-class-with-static-members/69878
61- static node *Head;
62- static node *Tail;
56+ static node *Head, *Tail;
6357
6458 public:
6559 // / Node in linked list of entries.
@@ -82,13 +76,7 @@ namespace llvm {
8276 // / add a node to the executable's registry. Therefore it's not defined here
8377 // / to avoid it being instantiated in the plugin and is instead defined in
8478 // / the executable (see LLVM_INSTANTIATE_REGISTRY below).
85- static void add_node (node *N) {
86- if (Tail)
87- Tail->Next = N;
88- else
89- Head = N;
90- Tail = N;
91- }
79+ static void add_node (node *N);
9280
9381 // / Iterators for registry entries.
9482 // /
@@ -107,7 +95,7 @@ namespace llvm {
10795
10896 // begin is not defined here in order to avoid usage of an undefined static
10997 // data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
110- static iterator begin () { return iterator (Head); }
98+ static iterator begin ();
11199 static iterator end () { return iterator (nullptr ); }
112100
113101 static iterator_range<iterator> entries () {
@@ -136,28 +124,36 @@ namespace llvm {
136124 }
137125 };
138126 };
139-
140127} // end namespace llvm
141128
142- #ifdef _WIN32
143129// / Instantiate a registry class.
144- #define LLVM_INSTANTIATE_REGISTRY (REGISTRY_CLASS ) \
145- namespace llvm { \
146- template <typename T> \
147- typename Registry<T>::node *Registry<T>::Head = nullptr ; \
148- template <typename T> \
149- typename Registry<T>::node *Registry<T>::Tail = nullptr ; \
150- template class LLVM_ABI_EXPORT Registry<REGISTRY_CLASS::type>; \
151- }
152- #else
153- #define LLVM_INSTANTIATE_REGISTRY (REGISTRY_CLASS ) \
154- namespace llvm { \
155- template <typename T> \
156- typename Registry<T>::node *Registry<T>::Head = nullptr ; \
157- template <typename T> \
158- typename Registry<T>::node *Registry<T>::Tail = nullptr ; \
159- template class Registry <REGISTRY_CLASS::type>; \
130+ // /
131+ // / This provides template definitions of add_node, begin, and the Head and Tail
132+ // / pointers, then explicitly instantiates them. We could explicitly specialize
133+ // / them, instead of the two-step process of define then instantiate, but
134+ // / strictly speaking that's not allowed by the C++ standard (we would need to
135+ // / have explicit specialization declarations in all translation units where the
136+ // / specialization is used) so we don't.
137+ #define LLVM_INSTANTIATE_REGISTRY (REGISTRY_CLASS ) \
138+ namespace llvm { \
139+ template <typename T> typename Registry<T>::node *Registry<T>::Head = nullptr ;\
140+ template <typename T> typename Registry<T>::node *Registry<T>::Tail = nullptr ;\
141+ template <typename T> \
142+ void Registry<T>::add_node(typename Registry<T>::node *N) { \
143+ if (Tail) \
144+ Tail->Next = N; \
145+ else \
146+ Head = N; \
147+ Tail = N; \
148+ } \
149+ template <typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150+ return iterator (Head); \
151+ } \
152+ template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Head; \
153+ template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Tail; \
154+ template \
155+ void Registry<REGISTRY_CLASS::type>::add_node(REGISTRY_CLASS::node*); \
156+ template REGISTRY_CLASS::iterator Registry<REGISTRY_CLASS::type>::begin(); \
160157 }
161- #endif
162158
163159#endif // LLVM_SUPPORT_REGISTRY_H
0 commit comments