From a5f1e9d6e8a9ee0ca0a73ae4e8049e6385dc5f2f Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 21 Sep 2025 12:41:03 -0700 Subject: [PATCH 1/2] [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 Registry::node *Registry::Head = nullptr; \ - template \ - typename Registry::node *Registry::Tail = nullptr; \ template class LLVM_ABI_EXPORT Registry; \ } #else #define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \ namespace llvm { \ - template \ - typename Registry::node *Registry::Head = nullptr; \ - template \ - typename Registry::node *Registry::Tail = nullptr; \ template class Registry; \ } #endif From 8331fadbfbff7167189e66ac770b19a8f80f0937 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 22 Sep 2025 23:23:27 -0700 Subject: [PATCH 2/2] Address a comment. --- llvm/include/llvm/Support/Registry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Support/Registry.h b/llvm/include/llvm/Support/Registry.h index e77a794a12994..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 - inline static node *Head = nullptr; - inline static node *Tail = nullptr; + static inline node *Head = nullptr; + static inline node *Tail = nullptr; public: /// Node in linked list of entries.