undefined reference to 'folly::threadlocal_detail::StaticMeta<void>::EntryID::kInvalid'
authorJody Ho <jodyho@fb.com>
Fri, 16 Oct 2015 01:51:01 +0000 (18:51 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Fri, 16 Oct 2015 02:20:20 +0000 (19:20 -0700)
Summary: In some cases, folly::threadlocal_detail::StaticMeta<void>::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
folly/test/ThreadLocalTest.cpp

index 6302be42415ed5aed6ac3d80d32c1d6c0f9806a9..691a5fa50d0dcae2542c88e74ff23ccf3401525e 100644 (file)
@@ -524,6 +524,9 @@ struct StaticMeta {
   }
 };
 
+template <class Tag>
+constexpr uint32_t StaticMeta<Tag>::EntryID::kInvalid;
+
 #ifdef FOLLY_TLD_USE_FOLLY_TLS
 template <class Tag>
 FOLLY_TLS ThreadEntry StaticMeta<Tag>::threadEntry_ = {nullptr, 0,
index a319c2f6580691500bd8f3beb7ffc2be45f06943..16d7a35cab78bd29cfc108cf2e206c6ac8e2ffce 100644 (file)
@@ -24,6 +24,7 @@
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
+#include <limits.h>
 #include <map>
 #include <mutex>
 #include <set>
@@ -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<void>::EntryID::kInvalid);
+  EXPECT_EQ(std::numeric_limits<uint32_t>::max(), *pInvalid);
+}
+
 class SimpleThreadCachedInt {
 
   class NewTag;