Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Sep 23, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/160235.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/Registry.h (+2-10)
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

@kazutakahirata kazutakahirata merged commit 2800ac2 into llvm:main Sep 23, 2025
9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250922_10TMP_Support_Registry branch September 23, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants