Skip to content

Commit 2800ac2

Browse files
[Support] Use "inline static" to initialize Registry (NFC) (#160235)
In C++17, we can initialize a static member variable with "inline static" as part of the class definition. With this, we can eliminate the out-of-line static initializers involving boilerplate template code.
1 parent 6995742 commit 2800ac2

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

llvm/include/llvm/Support/Registry.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ namespace llvm {
5858
// declaration causing error C2487 "member of dll interface class may not
5959
// be declared with dll interface".
6060
// https://developercommunity.visualstudio.com/t/c2487-in-dllexport-class-with-static-members/69878
61-
static node *Head;
62-
static node *Tail;
61+
static inline node *Head = nullptr;
62+
static inline node *Tail = nullptr;
6363

6464
public:
6565
/// Node in linked list of entries.
@@ -143,19 +143,11 @@ namespace llvm {
143143
/// Instantiate a registry class.
144144
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
145145
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; \
150146
template class LLVM_ABI_EXPORT Registry<REGISTRY_CLASS::type>; \
151147
}
152148
#else
153149
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
154150
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; \
159151
template class Registry<REGISTRY_CLASS::type>; \
160152
}
161153
#endif

0 commit comments

Comments
 (0)