diff mbox series

[ovs-dev] acinclude.m4: Really check whether GCC support -Wno-null-pointer-arithmetic.

Message ID 20180918091120.14083-1-blp@ovn.org
State Accepted
Headers show
Series [ovs-dev] acinclude.m4: Really check whether GCC support -Wno-null-pointer-arithmetic. | expand

Commit Message

Ben Pfaff Sept. 18, 2018, 9:11 a.m. UTC
I've noticed recently an annoying quantity of error messages like the
following in builds in various places:

    gcc: error: unrecognized command line option ‘-Wunknown-warning-option’

This didn't really make sense because OVS checks whether the compiler
supports warning options before it uses them.  Looking closer, the GCC
manual has a note that explains the issue:

     When an unrecognized warning option is requested (e.g.,
    '-Wunknown-warning'), GCC emits a diagnostic stating that the
    option is not recognized.  However, if the '-Wno-' form is used,
    the behavior is slightly different: no diagnostic is produced for
    '-Wno-unknown-warning' unless other diagnostics are being
    produced.  This allows the use of new '-Wno-' options with old
    compilers, but if something goes wrong, the compiler warns that
    an unrecognized option is present.

Thus, we can properly check only for the *positive* version of a warning
option, so this commit makes the OVS tests do that.

Fixes: a7021b08b0d5 ("configure: Disable -Wnull-pointer-arithmetic Clang warning.")
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 acinclude.m4 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Aaron Conole Sept. 26, 2018, 5:26 p.m. UTC | #1
Ben Pfaff <blp@ovn.org> writes:

> I've noticed recently an annoying quantity of error messages like the
> following in builds in various places:
>
>     gcc: error: unrecognized command line option ‘-Wunknown-warning-option’
>
> This didn't really make sense because OVS checks whether the compiler
> supports warning options before it uses them.  Looking closer, the GCC
> manual has a note that explains the issue:
>
>      When an unrecognized warning option is requested (e.g.,
>     '-Wunknown-warning'), GCC emits a diagnostic stating that the
>     option is not recognized.  However, if the '-Wno-' form is used,
>     the behavior is slightly different: no diagnostic is produced for
>     '-Wno-unknown-warning' unless other diagnostics are being
>     produced.  This allows the use of new '-Wno-' options with old
>     compilers, but if something goes wrong, the compiler warns that
>     an unrecognized option is present.
>
> Thus, we can properly check only for the *positive* version of a warning
> option, so this commit makes the OVS tests do that.
>
> Fixes: a7021b08b0d5 ("configure: Disable -Wnull-pointer-arithmetic Clang warning.")
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---

I didn't get a chance to test this out, but the change looks sane.

Acked-by: Aaron Conole <aconole@redhat.com>
Ben Pfaff Sept. 26, 2018, 8:24 p.m. UTC | #2
On Wed, Sep 26, 2018 at 01:26:46PM -0400, Aaron Conole wrote:
> Ben Pfaff <blp@ovn.org> writes:
> 
> > I've noticed recently an annoying quantity of error messages like the
> > following in builds in various places:
> >
> >     gcc: error: unrecognized command line option ‘-Wunknown-warning-option’
> >
> > This didn't really make sense because OVS checks whether the compiler
> > supports warning options before it uses them.  Looking closer, the GCC
> > manual has a note that explains the issue:
> >
> >      When an unrecognized warning option is requested (e.g.,
> >     '-Wunknown-warning'), GCC emits a diagnostic stating that the
> >     option is not recognized.  However, if the '-Wno-' form is used,
> >     the behavior is slightly different: no diagnostic is produced for
> >     '-Wno-unknown-warning' unless other diagnostics are being
> >     produced.  This allows the use of new '-Wno-' options with old
> >     compilers, but if something goes wrong, the compiler warns that
> >     an unrecognized option is present.
> >
> > Thus, we can properly check only for the *positive* version of a warning
> > option, so this commit makes the OVS tests do that.
> >
> > Fixes: a7021b08b0d5 ("configure: Disable -Wnull-pointer-arithmetic Clang warning.")
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > ---
> 
> I didn't get a chance to test this out, but the change looks sane.
> 
> Acked-by: Aaron Conole <aconole@redhat.com>

Thanks.  I applied this to master.
diff mbox series

Patch

diff --git a/acinclude.m4 b/acinclude.m4
index 0690baedfb9d..8d850349817f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -996,7 +996,11 @@  AC_DEFUN([_OVS_CHECK_CC_OPTION], [dnl
      dnl    gcc: unrecognized option '-Qunused-arguments'
      dnl    0
      dnl    %
-     CFLAGS="$CFLAGS $WERROR $1"
+     dnl
+     dnl In addition, GCC does not complain about a -Wno-<foo> option that
+     dnl it does not understand, unless it has another error to report, so
+     dnl instead of testing for -Wno-<foo>, test for the positive version.
+     CFLAGS="$CFLAGS $WERROR m4_bpatsubst([$1], [-Wno-], [-W])"
      AC_COMPILE_IFELSE(
        [AC_LANG_SOURCE([int x;])],
        [if test -s conftest.err && grep "unrecognized option" conftest.err