Add -Werror to -Wshadow-local and -Wshadow-compatible-local warning check
authorAaron Orenstein <aorenste@fb.com>
Tue, 21 Nov 2017 22:02:18 +0000 (14:02 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 21 Nov 2017 22:12:58 +0000 (14:12 -0800)
Summary:
Without -Werror Apple LLVM will print a warning about -Wshadow-local
and -Wshadow-compatible-local but won't fail.  This causes problems for
downstream code which uses -Werror.

Reviewed By: meyering

Differential Revision: D6375771

fbshipit-source-id: 4ac3a4ff46bdb76f1f07b0c8ba479a7d404c8c9b

folly/configure.ac

index 0e6aa379c1a82750bfb02d1b455c675f81e303a4..3ad0893443adac5c38502e12c7d13cd1d7e2dec6 100644 (file)
@@ -56,12 +56,35 @@ CXXFLAGS="$STD $CXXFLAGS"
 # expose required -std option via pkg-config
 PKG_CXXFLAGS=$STD
 
 # expose required -std option via pkg-config
 PKG_CXXFLAGS=$STD
 
+# See if -Wunknown-warning-option is supported
+AC_MSG_CHECKING(
+  [whether -Wunknown-warning-option is supported])
+AC_CACHE_VAL([folly_cv_cxx_unknown_warning_option_support], [
+  folly_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -Werror=unknown-warning-option"
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[]], [[]])],
+    [
+      # The compiler didn't completely error out on -Werror=unknown-warning-option
+      CXXFLAGS="$CXXFLAGS -Werror=unknown-warning-option -Wthis-is-an-unknown-option-that-should-error"
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([[]], [[]])],
+        [folly_cv_cxx_unknown_warning_option_support=no],
+        [folly_cv_cxx_unknown_warning_option_support=yes])
+    ],
+    [folly_cv_cxx_unknown_warning_option_support=no])
+  CXXFLAGS="$folly_save_CXXFLAGS"])
+AC_MSG_RESULT([$folly_cv_cxx_unknown_warning_option_support])
+
 # 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"
 # 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"
+  if test "$folly_cv_cxx_unknown_warning_option_support" = yes; then
+    CXXFLAGS="$CXXFLAGS -Werror=unknown-warning-option"
+  fi
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM([[]], [[]])],
     [folly_cv_cxx_shadow_local_support=yes],
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM([[]], [[]])],
     [folly_cv_cxx_shadow_local_support=yes],