Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNXpb-00067F-GA for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Apr 2020 08:19:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jNXpZ-0004RF-Do for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Apr 2020 08:19:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNXpZ-0004R7-0K for pgsql-hackers@lists.postgresql.org; Sun, 12 Apr 2020 08:19:05 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jNXpV-0007IT-2M for pgsql-hackers@lists.postgresql.org; Sun, 12 Apr 2020 08:19:03 +0000 Received: by mail-wm1-x342.google.com with SMTP id o81so1108924wmo.2 for ; Sun, 12 Apr 2020 01:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vINK/b/GX4wIuo8JX13FIGEYW9n16xMnj6GB9OQsgpg=; b=MfrJFTvCdsxVNC59V+ukdRece0k8QXBk/Y8GrYO5+sE9UXAiqtVArq+VhkMhpQ43MT dDBCiKnOXliEZjWWhiTjN3yyJYrHpJ9GavYwCXxN+j+df9XBm0qcukxGxfZbXeyclojb 4MRO/oFsHJlg+yMQbgTXEs2/CppFDgt1F6+veboHlDv8JK20dyQpR7ZB1OaYClo0FTFj 9zNFNajSNWbURsbj2ylD1BVMtLJaa9jGZ1e6EqVDsGcHkqF5AbZ6hxoqB9fQ5SZ3r6Yj FK0THEbac/WJEDmGDYeel2162RWiM+FVYR6qc1nqPYG9llaDjUQSk2kBcIPAD+ehjqqp gmlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vINK/b/GX4wIuo8JX13FIGEYW9n16xMnj6GB9OQsgpg=; b=ugELaGN3Tziq6f7G1tAsO9B3npz0a5Oj5/ps7CP/XKHO+8RN4ZEHJ7Ubmut3ywqsVW kE0D2sNJi5MYiYMlwCkJfOqJf2P2jkDUv+GaGrKHqdKUwJJIdcU3Prqp/WtFIlB6g6uX VUpxwceaEnqaRZO8wHkqJGYvH1PcPHiN7O4tc/GkMnji5u7ytowz4eEVUnjAZUFyqy9g +9rCQZ/GSRMWWPagUY9M8VFfy993h580+pV1Me+nJ99hffy2OJSwV1ogwVVNmp+BFLn9 YGPMVTYVKBqKVI9b1dzdCdprKyEx7h3yXX9ruxN+zP7mcx/4feicl9ehnYnQwjE2Klj9 +ZXw== X-Gm-Message-State: AGi0PubUCL/95lpBo0dJFkEEfJOCMZQ7xjPU+MAde0Jqn/GayjxFoMPy Q/lxxeSejT1KKTViRFQ77gBj+1NEPKw= X-Google-Smtp-Source: APiQypIG9E+3dXae/h23u7/4WghCeRUEXQPFOy6r6fYkMVr3nYx5BjzxOYHif8foGcvlqyKCElIUcg== X-Received: by 2002:a1c:5502:: with SMTP id j2mr12905687wmb.71.1586679539326; Sun, 12 Apr 2020 01:18:59 -0700 (PDT) Received: from nol ([2a01:e0a:c:bcf0:dbc8:f7e9:89ae:5cd7]) by smtp.gmail.com with ESMTPSA id p190sm9709348wmp.38.2020.04.12.01.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2020 01:18:58 -0700 (PDT) Date: Sun, 12 Apr 2020 10:18:25 +0200 From: Julien Rouhaud To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Add "-Wimplicit-fallthrough" to default flags (was Re: pgsql: Support FETCH FIRST WITH TIES) Message-ID: <20200412081825.qyo5vwwco3fv4gdo@nol> References: <25206.1586630854@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="krg643e6aslr3jlj" Content-Disposition: inline In-Reply-To: <25206.1586630854@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --krg643e6aslr3jlj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Apr 11, 2020 at 02:47:34PM -0400, Tom Lane wrote: > Julien Rouhaud writes: > > On Tue, Apr 7, 2020 at 10:28 PM Alvaro Herrera wrote: > >> Support FETCH FIRST WITH TIES > > > FTR I now get the following when compiling with -Wimplicit-fallthrough -Werror: > > Yeah, assorted buildfarm animals are mentioning that too. I wonder > if we should add that to the default warning options selected by > configure? I don't remember if that's been discussed before. > I'm all for it. It seems like a trap easy to catch up early, and we do want to enforce it anyway. I'm attaching a simple patch for that if needed, hopefully with the correct autoconf version. > > It seems that this fall-through comment: > > /* fall-through */ > > Is not recognized by my compiler (gcc (Gentoo 9.3.0 p1) 9.3.0). If > > that's something we should fix, PFA a naive patch for that. > > Hmm, I feel like this logic is baroque enough to need more of a rewrite > than that :-(. But not sure exactly what would be better, so your > patch seems reasonable for now. The comments could use some help too. Yes I just checked the state machine to make sure that the fallthrough was expected, but the comments are now way better, thanks! --krg643e6aslr3jlj Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v1-implicit-fallthrough.diff" diff --git a/configure b/configure index 83abe872aa..739b30d5fa 100755 --- a/configure +++ b/configure @@ -5552,6 +5552,97 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wmissing_format_attribute" = x"yes"; then fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wimplicit-fallthrough, for CFLAGS" >&5 +$as_echo_n "checking whether ${CC} supports -Wimplicit-fallthrough, for CFLAGS... " >&6; } +if ${pgac_cv_prog_CC_cflags__Wimplicit_fallthrough+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_save_CFLAGS=$CFLAGS +pgac_save_CC=$CC +CC=${CC} +CFLAGS="${CFLAGS} -Wimplicit-fallthrough" +ac_save_c_werror_flag=$ac_c_werror_flag +ac_c_werror_flag=yes +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + pgac_cv_prog_CC_cflags__Wimplicit_fallthrough=yes +else + pgac_cv_prog_CC_cflags__Wimplicit_fallthrough=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_c_werror_flag=$ac_save_c_werror_flag +CFLAGS="$pgac_save_CFLAGS" +CC="$pgac_save_CC" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wimplicit_fallthrough" >&5 +$as_echo "$pgac_cv_prog_CC_cflags__Wimplicit_fallthrough" >&6; } +if test x"$pgac_cv_prog_CC_cflags__Wimplicit_fallthrough" = x"yes"; then + CFLAGS="${CFLAGS} -Wimplicit-fallthrough" +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Wimplicit-fallthrough, for CXXFLAGS" >&5 +$as_echo_n "checking whether ${CXX} supports -Wimplicit-fallthrough, for CXXFLAGS... " >&6; } +if ${pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_save_CXXFLAGS=$CXXFLAGS +pgac_save_CXX=$CXX +CXX=${CXX} +CXXFLAGS="${CXXFLAGS} -Wimplicit-fallthrough" +ac_save_cxx_werror_flag=$ac_cxx_werror_flag +ac_cxx_werror_flag=yes +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough=yes +else + pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_cxx_werror_flag=$ac_save_cxx_werror_flag +CXXFLAGS="$pgac_save_CXXFLAGS" +CXX="$pgac_save_CXX" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough" >&5 +$as_echo "$pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough" >&6; } +if test x"$pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough" = x"yes"; then + CXXFLAGS="${CXXFLAGS} -Wimplicit-fallthrough" +fi + + # This was included in -Wall/-Wformat in older GCC versions { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wformat-security, for CFLAGS" >&5 diff --git a/configure.in b/configure.in index ecdf172396..49816a83dc 100644 --- a/configure.in +++ b/configure.in @@ -496,6 +496,8 @@ if test "$GCC" = yes -a "$ICC" = no; then PGAC_PROG_CXX_CFLAGS_OPT([-Wendif-labels]) PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute]) PGAC_PROG_CXX_CFLAGS_OPT([-Wmissing-format-attribute]) + PGAC_PROG_CC_CFLAGS_OPT([-Wimplicit-fallthrough]) + PGAC_PROG_CXX_CFLAGS_OPT([-Wimplicit-fallthrough]) # This was included in -Wall/-Wformat in older GCC versions PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security]) PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security]) --krg643e6aslr3jlj--