From ce4dec4c322aee6b9905be54bb67956d76270b65 Mon Sep 17 00:00:00 2001 From: Owen Yamauchi Date: Fri, 3 May 2013 09:25:39 -0700 Subject: [PATCH] Break dependency on features.h 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 | 26 -------------------------- folly/String.cpp | 3 +-- folly/ThreadLocal.h | 26 ++++---------------------- folly/configure.ac | 14 +++++++++++++- 4 files changed, 18 insertions(+), 51 deletions(-) diff --git a/folly/Portability.h b/folly/Portability.h index a317350c..ccd90380 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -26,32 +26,6 @@ #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 -# 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__ diff --git a/folly/String.cpp b/folly/String.cpp index cfcb3582..4f1303ee 100644 --- a/folly/String.cpp +++ b/folly/String.cpp @@ -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)); diff --git a/folly/ThreadLocal.h b/folly/ThreadLocal.h index 0663417f..b4c031e7 100644 --- a/folly/ThreadLocal.h +++ b/folly/ThreadLocal.h @@ -42,22 +42,6 @@ #include "folly/Likely.h" #include -// Use noexcept on gcc 4.6 or higher -#undef FOLLY_NOEXCEPT -#ifdef __GNUC__ -# ifdef HAVE_FEATURES_H -# include -# 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 Accessor accessAllThreads() const { - FOLLY_ASSERT(static_assert(!std::is_same::value, - "Must use a unique Tag to use the accessAllThreads feature")); + static_assert(!std::is_same::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_ */ diff --git a/folly/configure.ac b/folly/configure.ac index 21d8f4ad..8ec537db 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -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 \ -- 2.34.1