Break dependency on features.h
authorOwen Yamauchi <oyamauchi@fb.com>
Fri, 3 May 2013 16:25:39 +0000 (09:25 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 20 May 2013 18:01:27 +0000 (11:01 -0700)
Summary:
It doesn't exist on some systems (at least Mac OS X). We're only using
it for __GNUC_PREREQ, which is easy to provide our own definition for.

I moved the definitions of FOLLY_FINAL and FOLLY_OVERRIDE into
folly-config.h so we can autoconf them in the open-source build. The
hardcoded stuff for the internal build is a little ugly, unfortunately.

folly can't be built with gcc versions earlier than 4.6, so that check
in ThreadLocal.h is pointless by now. (Plus we use noexcept without a
macro wrapper all over the place.) That stuff was also not
clang-friendly. clang has supported static_assert since 2.9 and noexcept
since... I'm not sure but at least 3.0.

Test Plan:
fbconfig/fbmake runtests, with gcc 4.6 and 4.7. clang can't
build folly right now, but I verified separately that it supports
noexcept and static_assert.

Reviewed By: simpkins@fb.com

FB internal diff: D799143

folly/Portability.h
folly/String.cpp
folly/ThreadLocal.h
folly/configure.ac

index a317350c0fdb134bf2f7ad44049838fc034eeeef..ccd90380001c7d108230362238eef08549c4d011 100644 (file)
  #endif
 #endif
 
-// Define macro wrappers for C++11's "final" and "override" keywords, which
-// are supported in gcc 4.7 but not gcc 4.6.
-//
-// TODO(tudorb/agallagher): Autotoolize this.
-#undef FOLLY_FINAL
-#undef FOLLY_OVERRIDE
-
-#if defined(__clang__)
-#  define FOLLY_FINAL final
-#  define FOLLY_OVERRIDE override
-#elif defined(__GNUC__)
-# include <features.h>
-# if __GNUC_PREREQ(4,7)
-#  define FOLLY_FINAL final
-#  define FOLLY_OVERRIDE override
-# endif
-#endif
-
-#ifndef FOLLY_FINAL
-# define FOLLY_FINAL
-#endif
-
-#ifndef FOLLY_OVERRIDE
-# define FOLLY_OVERRIDE
-#endif
-
 
 // MaxAlign: max_align_t isn't supported by gcc
 #ifdef __GNUC__
index cfcb3582104b67a210cfa847b3830d0b1197e090..4f1303eeaa9f44c643d4b15b404e46f4880d1a17 100644 (file)
@@ -242,8 +242,7 @@ fbstring errnoStr(int err) {
   fbstring result;
 
   // http://www.kernel.org/doc/man-pages/online/pages/man3/strerror.3.html
-#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || \
-     !FOLLY_HAVE_FEATURES_H) && !_GNU_SOURCE
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE
   // Using XSI-compatible strerror_r
   int r = strerror_r(err, buf, sizeof(buf));
 
index 0663417f1f7fe0d7f46e54f299fa09284216cd0c..b4c031e750b3d8d2b0a47e863918ade33b313b4e 100644 (file)
 #include "folly/Likely.h"
 #include <type_traits>
 
-// Use noexcept on gcc 4.6 or higher
-#undef FOLLY_NOEXCEPT
-#ifdef __GNUC__
-# ifdef HAVE_FEATURES_H
-#  include <features.h>
-#  if __GNUC_PREREQ(4,6)
-#    define FOLLY_NOEXCEPT noexcept
-#    define FOLLY_ASSERT(x) x
-#  endif
-# endif
-#endif
-
-#ifndef FOLLY_NOEXCEPT
-#  define FOLLY_NOEXCEPT
-#  define FOLLY_ASSERT(x) /**/
-#endif
 
 namespace folly {
 enum class TLPDestructionMode {
@@ -283,7 +267,7 @@ class ThreadLocalPtr {
     Accessor(const Accessor&) = delete;
     Accessor& operator=(const Accessor&) = delete;
 
-    Accessor(Accessor&& other) FOLLY_NOEXCEPT
+    Accessor(Accessor&& other) noexcept
       : meta_(other.meta_),
         lock_(other.lock_),
         id_(other.id_) {
@@ -291,7 +275,7 @@ class ThreadLocalPtr {
       other.lock_ = nullptr;
     }
 
-    Accessor& operator=(Accessor&& other) FOLLY_NOEXCEPT {
+    Accessor& operator=(Accessor&& other) noexcept {
       // Each Tag has its own unique meta, and accessors with different Tags
       // have different types.  So either *this is empty, or this and other
       // have the same tag.  But if they have the same tag, they have the same
@@ -331,8 +315,8 @@ class ThreadLocalPtr {
   // accessor allows a client to iterate through all thread local child
   // elements of this ThreadLocal instance.  Holds a global lock for each <Tag>
   Accessor accessAllThreads() const {
-    FOLLY_ASSERT(static_assert(!std::is_same<Tag, void>::value,
-                 "Must use a unique Tag to use the accessAllThreads feature"));
+    static_assert(!std::is_same<Tag, void>::value,
+                  "Must use a unique Tag to use the accessAllThreads feature");
     return Accessor(id_);
   }
 
@@ -350,8 +334,6 @@ class ThreadLocalPtr {
   int id_;  // every instantiation has a unique id
 };
 
-#undef FOLLY_NOEXCEPT
-
 }  // namespace folly
 
 #endif /* FOLLY_THREADLOCAL_H_ */
index 21d8f4adb9f659e64b23a27510cd2facd36403ac..8ec537db4f39cd3aaf891a4d84ba6a2b2233439e 100644 (file)
@@ -38,7 +38,7 @@ AX_BOOST_SYSTEM
 
 # Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h features.h malloc.h emmintrin.h])
+AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h malloc.h emmintrin.h])
 
 AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
                 [Couldn't find double-conversion.h, please download from \
@@ -63,6 +63,18 @@ AC_COMPILE_IFELSE(
   [AC_DEFINE([HAVE_IFUNC], [1], [Define to 1 if the compiler supports ifunc])],
   [AC_DEFINE([HAVE_IFUNC], [0], [Define to 0 if the compiler doesn't support ifunc])]
 )
+AC_COMPILE_IFELSE(
+  [AC_LANG_SOURCE[class C { virtual void f() final {} virtual void g() {} };
+                  class D : public C { virtual void g() override {} };]],
+  [AC_DEFINE([FINAL], [final],
+             [Define to "final" if the compiler supports C++11 "final"]),
+   AC_DEFINE([OVERRIDE], [override],
+             [Define to "override" if the compiler supports C++11 "override"])],
+  [AC_DEFINE([FINAL], [],
+             [Define to "final" if the compiler supports C++11 "final"]),
+   AC_DEFINE([OVERRIDE], [],
+             [Define to "override" if the compiler supports C++11 "override"])]
+)
 
 # Checks for library functions.
 AC_CHECK_FUNCS([getdelim \