[llvm v3.6.2+] BROKEN: g++-4.9: error: unrecognized command line option '-Wcovered-switch-default'

Hi,

I try to compile LLVM/Clang v3.6.2 with gcc/g++ v4.9, this fails after
configure like this...

[ build-log]
...
llvm[0]: Constructing LLVMBuild project information.
make[1]: Entering directory
`/home/wearefam/src/llvm-toolchain/llvm-build/lib/Support'
llvm[1]: Compiling APFloat.cpp for Release+Asserts build
g++-4.9: error: unrecognized command line option '-Wcovered-switch-default'
/bin/rm: cannot remove
`/home/wearefam/src/llvm-toolchain/llvm-build/lib/Support/Release+Asserts/APFloat.d.tmp':
No such file or directory
make[1]: *** [/home/wearefam/src/llvm-toolchain/llvm-build/lib/Support/Release+Asserts/APFloat.o]
Error 1
make[1]: Leaving directory
`/home/wearefam/src/llvm-toolchain/llvm-build/lib/Support'
...

'-Wcovered-switch-default' is really an unrecognized command line
option for g++, but it is set after configure has done its work (see
[1]).

[ configure-log ]
...
checking optional compiler flags... -Wno-variadic-macros
-Wno-missing-field-initializers -Wcovered-switch-default
-Wno-uninitialized -Wno-comment
...

Why is '-Wcovered-switch-default' set? It is unrecognized!

Not sure if this workaround below is good or not.

[ llvm/autoconf/configure.ac ]
...
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])
# XXX: Workaround: g++-4.9: error: unrecognized command line option
'-Wcovered-switch-default'
if test "$GXX" = "yes"
  COVERED_SWITCH_DEFAULT=
else
CXX_FLAG_CHECK(COVERED_SWITCH_DEFAULT, [-Wcovered-switch-default])
fi
...

I checked Wild Wild Internet, but what is the adequate command line
option for g++?

I followed the BR in [3] and [4] gave no clear information on this.

GCC online-docs [1] lists these warning-options:
...
[ -Wswitch ]
Warn whenever a switch statement has an index of enumerated type and
lacks a case for one or more of the named codes of that enumeration.
(The presence of a default label prevents this warning.) case labels
outside the enumeration range also provoke warnings when this option
is used (even if there is a default label). This warning is enabled by
-Wall.

[ -Wswitch-default ]
Warn whenever a switch statement does not have a default case.

[ -Wswitch-enum ]
Warn whenever a switch statement has an index of enumerated type and
lacks a case for one or more of the named codes of that enumeration.
case labels outside the enumeration range also provoke warnings when
this option is used. The only difference between -Wswitch and this
option is that this option gives a warning about an omitted
enumeration code even if there is a default label.

[ -Wswitch-bool ]
Warn whenever a switch statement has an index of boolean type and the
case values are outside the range of a boolean type. It is possible to
suppress this warning by casting the controlling expression to a type
other than bool. For example:

          switch ((int) (a == 4))
            {
            ...
            }

This warning is enabled by default for C and C++ programs.
...

In my workaround-snippet I unset COVERED_SWITCH_DEFAULT.

Comments?

Thanks in advance.

Regards,
- Sedat -

P.S.: I have attached my build-script and the outputs of my configure
and build logs.

[1] Warning Options (Using the GNU Compiler Collection (GCC))
[2] http://stackoverflow.com/questions/5402745/gcc-switch-on-enum-retain-missing-warning-but-use-default
[3] 61864 – -Wcovered-switch-default to identify "dead" default branch
[4] design - Why does Clang/LLVM warn me about using default in a switch statement where all enumerated cases are covered? - Software Engineering Stack Exchange

build-log_llvm-toolchain-3.6.2.txt (628 Bytes)

build_llvm-toolchain.sh (1.57 KB)

configure-log_llvm-toolchain-3.6.2.txt (10.1 KB)

Hi,

my configure-line requires CC and CXX set (like in the make-line).

[ build-script ]
...
[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
cd $BUILD_DIR

../llvm/configure CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD --prefix=$PREFIX
$CFG_OPTS 2>&1 | tee $LOGS_DIR/$CFG_LOG_FILE

$MAKE CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $MAKE_OPTS 2>&1 | tee
$LOGS_DIR/$BUILD_LOG_FILE
...

So this looks good now.

$ egrep 'CC=|CXX=|COVERED_SWITCH_DEFAULT=' llvm-build/config.log
  $ ../llvm/configure CC=gcc-4.9 CXX=g++-4.9
--prefix=/opt/llvm-toolchain-3.6.2 --enable-optimized
--enable-assertions --enable-targets=host-only
COLLECT_GCC=gcc-4.9
COLLECT_GCC=g++-4.9
BUILD_CC=''
BUILD_CXX=''
CC='gcc-4.9'
COVERED_SWITCH_DEFAULT=''
CXX='g++-4.9'
ENABLE_EMBED_STDCXX='0'
ac_ct_CC=''
ac_ct_CXX=''

Just as a note: With LLVM/Clang v3.6.1 and prior I did not need to
pass CC/CXX to my configure-line.

Regards,
- Sedat -