From: Jody Ho Date: Fri, 16 Oct 2015 01:51:01 +0000 (-0700) Subject: undefined reference to 'folly::threadlocal_detail::StaticMeta::EntryID::kInvalid' X-Git-Tag: deprecate-dynamic-initializer~324 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=77a85008801bae6d8bf7767dc2b0e8542373cd4a;p=folly.git 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 --- 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;