@@ -53,13 +53,7 @@ namespace llvm {
53
53
Registry () = delete ;
54
54
55
55
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;
63
57
64
58
public:
65
59
// / Node in linked list of entries.
@@ -82,13 +76,7 @@ namespace llvm {
82
76
// / add a node to the executable's registry. Therefore it's not defined here
83
77
// / to avoid it being instantiated in the plugin and is instead defined in
84
78
// / 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);
92
80
93
81
// / Iterators for registry entries.
94
82
// /
@@ -107,7 +95,7 @@ namespace llvm {
107
95
108
96
// begin is not defined here in order to avoid usage of an undefined static
109
97
// data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
110
- static iterator begin () { return iterator (Head); }
98
+ static iterator begin ();
111
99
static iterator end () { return iterator (nullptr ); }
112
100
113
101
static iterator_range<iterator> entries () {
@@ -136,28 +124,36 @@ namespace llvm {
136
124
}
137
125
};
138
126
};
139
-
140
127
} // end namespace llvm
141
128
142
- #ifdef _WIN32
143
129
// / 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(); \
160
157
}
161
- #endif
162
158
163
159
#endif // LLVM_SUPPORT_REGISTRY_H
0 commit comments