From 1983f54daebc5b4ba0ebb3fbc6ec0abb083f8908 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 31 Jan 2013 22:19:12 +0000 Subject: [PATCH] Add -Wno-nested-anon-types to -pedantic builds of LLVM. This Clang warning catches uses of an extremely minor and widely-available C++ extension (which every C++ compiler I could find supports, but EDG and Clang reject in strict mode). The diagnosed code pattern looks like this: struct X { union { struct { int a; int b; } S; }; }; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174103 91177308-0d34-0410-b5e6-96231b3b80d8 --- Makefile.config.in | 2 ++ Makefile.rules | 2 +- autoconf/configure.ac | 3 ++- cmake/modules/HandleLLVMOptions.cmake | 4 ++++ configure | 8 ++++++-- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile.config.in b/Makefile.config.in index f0f2e0d9ec8..c751a0176d6 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -366,6 +366,8 @@ COVERED_SWITCH_DEFAULT = @COVERED_SWITCH_DEFAULT@ NO_UNINITIALIZED = @NO_UNINITIALIZED@ # -Wno-maybe-uninitialized NO_MAYBE_UNINITIALIZED = @NO_MAYBE_UNINITIALIZED@ +# -Wno-nested-anon-types +NO_NESTED_ANON_TYPES = @NO_NESTED_ANON_TYPES@ # Was polly found in tools/polly? LLVM_HAS_POLLY = @LLVM_HAS_POLLY@ diff --git a/Makefile.rules b/Makefile.rules index 1e646009419..6abd3934c7b 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -665,7 +665,7 @@ LD.Flags += $(EXTRA_LD_OPTIONS) endif ifndef NO_PEDANTIC -CompileCommonOpts += -pedantic -Wno-long-long +CompileCommonOpts += -pedantic -Wno-long-long $(NO_NESTED_ANON_TYPES) endif CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \ $(EXTRA_OPTIONS) $(COVERED_SWITCH_DEFAULT) \ diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 21c3eeba534..0a291c109b1 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -1264,6 +1264,7 @@ dnl Check optional compiler flags. AC_MSG_CHECKING([optional compiler flags]) CXX_FLAG_CHECK(NO_VARIADIC_MACROS, [-Wno-variadic-macros]) CXX_FLAG_CHECK(NO_MISSING_FIELD_INITIALIZERS, [-Wno-missing-field-initializers]) +CXX_FLAG_CHECK(NO_NESTED_ANON_TYPES, [-Wno-nested-anon-types]) CXX_FLAG_CHECK(COVERED_SWITCH_DEFAULT, [-Wcovered-switch-default]) dnl GCC's potential uninitialized use analysis is weak and presents lots of dnl false positives, so disable it. @@ -1299,7 +1300,7 @@ else NO_UNINITIALIZED= NO_MAYBE_UNINITIALIZED= fi -AC_MSG_RESULT([$NO_VARIADIC_MACROS $NO_MISSING_FIELD_INITIALIZERS $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED]) +AC_MSG_RESULT([$NO_VARIADIC_MACROS $NO_MISSING_FIELD_INITIALIZERS $NO_NESTED_ANON_TYPES $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED]) AC_ARG_WITH([python], [AS_HELP_STRING([--with-python], [path to python])], diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index bb1085c0143..3cf1ef20e41 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -193,6 +193,10 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) if (LLVM_ENABLE_PEDANTIC) add_llvm_definitions( -pedantic -Wno-long-long ) + check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG) + if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" ) + endif() endif (LLVM_ENABLE_PEDANTIC) check_cxx_compiler_flag("-Werror -Wcovered-switch-default" CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG) if( CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG ) diff --git a/configure b/configure index 9e74ab61b60..8dcbaf3f171 100755 --- a/configure +++ b/configure @@ -766,6 +766,7 @@ CONVENIENCE_LTDL_FALSE LIBADD_DL NO_VARIADIC_MACROS NO_MISSING_FIELD_INITIALIZERS +NO_NESTED_ANON_TYPES COVERED_SWITCH_DEFAULT NO_MAYBE_UNINITIALIZED NO_UNINITIALIZED @@ -12260,6 +12261,8 @@ NO_VARIADIC_MACROS=`$CXX -Werror -Wno-variadic-macros -fsyntax-only -xc /dev/nul NO_MISSING_FIELD_INITIALIZERS=`$CXX -Werror -Wno-missing-field-initializers -fsyntax-only -xc /dev/null 2>/dev/null && echo -Wno-missing-field-initializers` +NO_NESTED_ANON_TYPES=`$CXX -Werror -Wno-nested-anon-types -fsyntax-only -xc /dev/null 2>/dev/null && echo -Wno-nested-anon-types` + COVERED_SWITCH_DEFAULT=`$CXX -Werror -Wcovered-switch-default -fsyntax-only -xc /dev/null 2>/dev/null && echo -Wcovered-switch-default` if test "$GXX" = "yes" @@ -12289,8 +12292,8 @@ else NO_UNINITIALIZED= NO_MAYBE_UNINITIALIZED= fi -{ echo "$as_me:$LINENO: result: $NO_VARIADIC_MACROS $NO_MISSING_FIELD_INITIALIZERS $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED" >&5 -echo "${ECHO_T}$NO_VARIADIC_MACROS $NO_MISSING_FIELD_INITIALIZERS $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED" >&6; } +{ echo "$as_me:$LINENO: result: $NO_VARIADIC_MACROS $NO_MISSING_FIELD_INITIALIZERS $NO_NESTED_ANON_TYPES $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED" >&5 +echo "${ECHO_T}$NO_VARIADIC_MACROS $NO_MISSING_FIELD_INITIALIZERS $NO_NESTED_ANON_TYPES $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED" >&6; } # Check whether --with-python was given. @@ -22478,6 +22481,7 @@ CONVENIENCE_LTDL_FALSE!$CONVENIENCE_LTDL_FALSE$ac_delim LIBADD_DL!$LIBADD_DL$ac_delim NO_VARIADIC_MACROS!$NO_VARIADIC_MACROS$ac_delim NO_MISSING_FIELD_INITIALIZERS!$NO_MISSING_FIELD_INITIALIZERS$ac_delim +NO_NESTED_ANON_TYPES!$NO_NESTED_ANON_TYPES$ac_delim COVERED_SWITCH_DEFAULT!$COVERED_SWITCH_DEFAULT$ac_delim NO_MAYBE_UNINITIALIZED!$NO_MAYBE_UNINITIALIZED$ac_delim NO_UNINITIALIZED!$NO_UNINITIALIZED$ac_delim