[llvm] [Support] Use "inline static" to initialize Registry (NFC) (PR #160235)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 22:43:30 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From a5f1e9d6e8a9ee0ca0a73ae4e8049e6385dc5f2f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 21 Sep 2025 12:41:03 -0700
Subject: [PATCH] [Support] Use "inline static" to initialize Registry (NFC)
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.
---
llvm/include/llvm/Support/Registry.h | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/Support/Registry.h b/llvm/include/llvm/Support/Registry.h
index ff9226c39359c..e77a794a12994 100644
--- a/llvm/include/llvm/Support/Registry.h
+++ b/llvm/include/llvm/Support/Registry.h
@@ -58,8 +58,8 @@ namespace llvm {
// declaration causing error C2487 "member of dll interface class may not
// be declared with dll interface".
// https://developercommunity.visualstudio.com/t/c2487-in-dllexport-class-with-static-members/69878
- static node *Head;
- static node *Tail;
+ inline static node *Head = nullptr;
+ inline static node *Tail = nullptr;
public:
/// Node in linked list of entries.
@@ -143,19 +143,11 @@ namespace llvm {
/// Instantiate a registry class.
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
namespace llvm { \
- template <typename T> \
- typename Registry<T>::node *Registry<T>::Head = nullptr; \
- template <typename T> \
- typename Registry<T>::node *Registry<T>::Tail = nullptr; \
template class LLVM_ABI_EXPORT Registry<REGISTRY_CLASS::type>; \
}
#else
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
namespace llvm { \
- template <typename T> \
- typename Registry<T>::node *Registry<T>::Head = nullptr; \
- template <typename T> \
- typename Registry<T>::node *Registry<T>::Tail = nullptr; \
template class Registry<REGISTRY_CLASS::type>; \
}
#endif
More information about the llvm-commits
mailing list