From 77a85008801bae6d8bf7767dc2b0e8542373cd4a Mon Sep 17 00:00:00 2001 From: Jody Ho Date: Thu, 15 Oct 2015 18:51:01 -0700 Subject: [PATCH] undefined reference to 'folly::threadlocal_detail::StaticMeta::EntryID::kInvalid' Summary: In some cases, folly::threadlocal_detail::StaticMeta::EntryID::kInvalid is odr-used, a definition at the namespace scope is required even though it has been initialized with a brace-or-equal initializer. See http://en.cppreference.com/w/cpp/language/static Reviewed By: @yfeldblum Differential Revision: D2548668 fb-gh-sync-id: 9cd6d7b2f37d1481d1adbf4f0a2d9e66631efd15 --- folly/detail/ThreadLocalDetail.h | 3 +++ folly/test/ThreadLocalTest.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/folly/detail/ThreadLocalDetail.h b/folly/detail/ThreadLocalDetail.h index 6302be42..691a5fa5 100644 --- a/folly/detail/ThreadLocalDetail.h +++ b/folly/detail/ThreadLocalDetail.h @@ -524,6 +524,9 @@ struct StaticMeta { } }; +template +constexpr uint32_t StaticMeta::EntryID::kInvalid; + #ifdef FOLLY_TLD_USE_FOLLY_TLS template FOLLY_TLS ThreadEntry StaticMeta::threadEntry_ = {nullptr, 0, diff --git a/folly/test/ThreadLocalTest.cpp b/folly/test/ThreadLocalTest.cpp index a319c2f6..16d7a35c 100644 --- a/folly/test/ThreadLocalTest.cpp +++ b/folly/test/ThreadLocalTest.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -249,6 +250,14 @@ TEST(ThreadLocal, InterleavedDestructors) { EXPECT_EQ(wVersionMax * 10, Widget::totalVal_); } +TEST(ThreadLocalPtr, ODRUseEntryIDkInvalid) { + // EntryID::kInvalid is odr-used + // see http://en.cppreference.com/w/cpp/language/static + const uint32_t* pInvalid = + &(threadlocal_detail::StaticMeta::EntryID::kInvalid); + EXPECT_EQ(std::numeric_limits::max(), *pInvalid); +} + class SimpleThreadCachedInt { class NewTag; -- 2.34.1