diff --git a/src/ds/defines.h b/src/ds/defines.h index e67e36d..a240739 100644 --- a/src/ds/defines.h +++ b/src/ds/defines.h @@ -20,6 +20,14 @@ # define SNMALLOC_COLD __attribute__((cold)) #endif +#if defined(__cpp_constinit) && __cpp_constinit >= 201907 +# define SNMALLOC_CONSTINIT_FN constinit +# define SNMALLOC_CONSTINIT_STATIC constinit const +#else +# define SNMALLOC_CONSTINIT_FN constexpr +# define SNMALLOC_CONSTINIT_STATIC constexpr +#endif + #if !defined(__clang__) && defined(__GNUC__) # define GCC_NOT_CLANG #endif diff --git a/src/pal/pal_bsd_aligned.h b/src/pal/pal_bsd_aligned.h index c93eb4c..bac3e82 100644 --- a/src/pal/pal_bsd_aligned.h +++ b/src/pal/pal_bsd_aligned.h @@ -23,7 +23,7 @@ namespace snmalloc static constexpr uint64_t pal_features = AlignedAllocation | PALBSD::pal_features; - static constexpr size_t minimum_alloc_size = 4096; + static SNMALLOC_CONSTINIT_STATIC size_t minimum_alloc_size = 4096; /** * Reserve memory at a specific alignment. diff --git a/src/pal/pal_windows.h b/src/pal/pal_windows.h index 3c95525..847a04b 100644 --- a/src/pal/pal_windows.h +++ b/src/pal/pal_windows.h @@ -58,7 +58,7 @@ namespace snmalloc # endif ; - static constexpr size_t minimum_alloc_size = 0x10000; + static SNMALLOC_CONSTINIT_STATIC size_t minimum_alloc_size = 0x10000; static constexpr size_t page_size = 0x1000;