[llvm] 2800ac2 - [Support] Use "inline static" to initialize Registry (NFC) (#160235)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 23 08:11:04 PDT 2025
Author: Kazu Hirata
Date: 2025-09-23T08:11:00-07:00
New Revision: 2800ac203cba9e82f31334ff5439b9a91f7444fa
URL: https://github.com/llvm/llvm-project/commit/2800ac203cba9e82f31334ff5439b9a91f7444fa
DIFF: https://github.com/llvm/llvm-project/commit/2800ac203cba9e82f31334ff5439b9a91f7444fa.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Support/Registry.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Registry.h b/llvm/include/llvm/Support/Registry.h
index ff9226c39359c..c02f15e5e32b8 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;
+ static inline node *Head = nullptr;
+ static inline 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