configure.ac: check for -Wshadow-local and -Wshadow-compatible-local
authorJim Meyering <meyering@fb.com>
Thu, 20 Oct 2016 14:50:18 +0000 (07:50 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Thu, 20 Oct 2016 14:53:56 +0000 (07:53 -0700)
Summary:
Add a configure-time check for whether -Wshadow-local and
-Wshadow-compatible-local are supported.  If so, arrange to
define HAVE_SHADOW_LOCAL_WARNINGS.

In Portability.h, use that new symbol to choose whether
to define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS, which
used pragmas to disable those new warnings.

Differential Revision: D4041696

fbshipit-source-id: 520ee88ae55147a13d0a045aca7d86567a8da99d

folly/Portability.h
folly/configure.ac

index 98ecd0300a31140c49b0c37a9951b484c7fcac69..4dbc3bd3b4bebada18013005beabde0b4e88bad8 100644 (file)
@@ -167,6 +167,14 @@ constexpr bool kHasUnalignedAccess = false;
 # define FOLLY_MSVC_DISABLE_WARNING(warningNumber)
 #endif
 
+#ifdef HAVE_SHADOW_LOCAL_WARNINGS
+#define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS        \
+  FOLLY_GCC_DISABLE_WARNING(shadow-compatible-local) \
+  FOLLY_GCC_DISABLE_WARNING(shadow-local)
+#else
+#define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS /* empty */
+#endif
+
 #if defined(__GNUC__) && !defined(__APPLE__) && !__GNUC_PREREQ(4,9)
 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56019
 // gcc 4.8.x incorrectly placed max_align_t in the root namespace
index 21cc2ce25ae6af4dddaf54f1346505617becc648..d4acc99bbf3efc1237878bf51494e991f5a087e5 100644 (file)
@@ -63,6 +63,23 @@ CXXFLAGS="$STD $CXXFLAGS"
 # expose required -std option via pkg-config
 PKG_CXXFLAGS=$STD
 
+# See if -Wshadow-local and -Wshadow-compatible-local are supported
+AC_MSG_CHECKING(
+  [whether -Wshadow-local and -Wshadow-compatible-local are supported])
+AC_CACHE_VAL([folly_cv_cxx_shadow_local_support], [
+  folly_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -Wshadow-local -Wshadow-compatible-local"
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[]], [[]])],
+    [folly_cv_cxx_shadow_local_support=yes],
+    [folly_cv_cxx_shadow_local_support=no])
+  CXXFLAGS="$folly_save_CXXFLAGS"])
+AC_MSG_RESULT([$folly_cv_cxx_shadow_local_support])
+if test "$folly_cv_cxx_shadow_local_support" = yes; then
+  AC_DEFINE([HAVE_SHADOW_LOCAL_WARNINGS], [1],
+  [Define if both -Wshadow-local and -Wshadow-compatible-local are supported.])
+fi
+
 # Checks for glog and gflags
 # There are no symbols with C linkage, so we do a try-run
 AC_HAVE_LIBRARY([gflags],[],[AC_MSG_ERROR(