Commit Graph

24 Commits

Author SHA1 Message Date
Lubomir Rintel
e2071e92f0 build: set -Wall when probing extra warning options
Some warnings depends on others: -Wformat-security won't work without
-Wformat. With -Wall we're confident enough that we have important
warnings enabled and in any case we're going to enable it anyway.

https://github.com/NetworkManager/NetworkManager/pull/175
2018-08-07 16:58:36 +02:00
Thomas Haller
b9bc20f4da build: pass -std=gnu99 to compiler
With --enable-more-warnings, we already used -std=gnu99, see
commit ba2b2de3ad.

Compilation may behave differently depending on the selected
C standard that we choose. It seems wrong, with more-warnings,
to build against a C standard, while otherwise leaving it undefind.

Indeed, one might argue, that our build system should not use
such compiler specific options. At least, not without detecting
support for the compiler option during ./configure.

However:

- we already did this for --enable-more-warnings.

- we should not program against a theoretical compiler. In practice,
  only gcc and clang works to build NetworkManager. Both these compilers
  support this option, so there is no reason to not use it. If we ever
  come into the situation to support another compiler, adjusting -std=gnu99
  will be the smallest problem. Until that happens (and that's far from
  imminent), don't pretend to be portable to non-existing compilers and
  use the flag that in practice is available.

See-also: https://gcc.gnu.org/onlinedocs/gcc/Standards.html
2018-07-17 17:46:39 +02:00
Thomas Haller
cc12413c08 m4/trivial: fix indentation 2018-07-17 17:42:24 +02:00
Lubomir Rintel
0999ebdf6d m4: parametrize flags variable
Make it possible to add compiler options to a different variable than
CFLAGS. This is useful to conditionally disable a compiler warning for a
subpart of a tree.
2018-02-16 16:06:59 +01:00
Lubomir Rintel
422e87ec0d m4/trivial: add a bug link to a compiler warning check 2018-02-08 17:11:46 +01:00
Lubomir Rintel
631982a796 m4: disable -Wcast-function-type
This fixes the GCC 8 build. It disables the warning conditionally so that we
get the warning back if glib gets fixed.
2018-02-07 11:46:56 +01:00
Lubomir Rintel
e912b36d95 build: enable unused-but-set warning
It was disabled for shady reasons (not checking write() return value)
that are long gone. Worse even, it hid some real bugs.
2017-12-18 13:29:32 +01:00
Thomas Haller
9c3402aa1e build: add "-Wvla" to warn about uses of variable-length arrays
We don't use them, so add a compiler warning about their use.
I think they are annoying, because sizeof(x) and typeof(x) might
evaluate at runtime. Especially the typeof() extension is useful
for macros, but behaves badly with variable-length arrays due to
running code at runtime.

But the worst is, G_STATIC_ASSERT() is implemented by declaring
an array of negative length. Usually, the checked condition should
be a compile time constant, but with VLAs the compiler would not evaluate
the static-assert at compile time and instead accept it silently. It's easy
to mess up static asserts to wrongly have a non-constant condition,
especially when the static-assert is used inside a macro.

Just say no.
2017-12-15 11:48:38 +01:00
Thomas Haller
41e7fca597 build: enable -Wlogical-op and -Wshift-negative-value compiler warning 2017-05-18 18:21:27 +02:00
Lubomir Rintel
928d68d04a m4: disable -Wmissing-braces for newer clang
src/NetworkManagerUtils.c:347:18: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
          NMIPAddr a1 = { 0 }, a2 = { 0 };
                          ^
                          {}

Should we initialize unions this way? I think it's all right -- the initializer
works well and { { { 0 } } } is probably not what we'd like to see.

(cherry picked from commit 43012156a3)
2017-04-18 09:44:45 +02:00
Thomas Haller
923c52ffbb build: test for support of -flto compiler flag
... and prepend the $ld_gc_flags instead of appending to the $CFLAGS.
2017-02-10 12:53:32 +01:00
Thomas Haller
a981c6c355 build: add m4 macros for --enable-lto and --enable-ld-gc 2017-02-10 12:11:21 +01:00
Thomas Haller
4a72c121ed build: reorder flags in "m4/compiler_options.m4"
Mostly sort alphabetically, but
  - keep -Wextra first
  - move "-Wno-*" flags to the end
2017-02-06 19:27:21 +01:00
Thomas Haller
5120205f98 build: enable -Wextra warning 2017-02-06 19:27:21 +01:00
Thomas Haller
705e63a292 build: disable -Wformat-truncation warning
The warning seems questionable and overly strict.
For now, just disable it to allow building with gcc7.

    src/systemd/src/basic/time-util.c: In function ‘format_timespan’:
    src/systemd/src/basic/time-util.c:509:46: error: ‘%0*lu’ directive output between 1 and 2147483648 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-truncation=]
                                                  "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                                  ^~~~
    src/systemd/src/basic/time-util.c:509:60: note: format string is defined here
                                                  "%s"USEC_FMT".%0*"PRI_USEC"%s",
    src/systemd/src/basic/time-util.c:509:46: note: directive argument in the range [0, 18446744073709551614]
                                                  "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                                  ^~~~

https://mail.gnome.org/archives/networkmanager-list/2017-February/msg00001.html
2017-02-06 16:53:37 +01:00
Thomas Haller
4b9cebd8ad build: enable -Wimplicit-fallthrough warning from gcc7 2017-02-06 16:45:20 +01:00
Thomas Haller
6bd9f5361f m4/compiler_options.m4: add line breaks for compiler options to check
No change in behavior.
2017-02-06 14:24:28 +01:00
Lubomir Rintel
fd47a9a762 build: move the --enable-more-warning option from m4/ to configure.ac
It will make it easier to policy the default.

(cherry picked from commit 8647be3717)
2017-01-19 16:15:30 +01:00
Thomas Haller
ba2b2de3ad build: allow using GCC C99 dialect instead of C89
We already use several GCC extenions, like typeof() and
__attribute__((cleanup)). They are too convinient to miss
and every supported compiler must support these.
Currently, gcc and clang does. Maybe other compilers would
support that too, but who knows, nobody seems to test that.

We also already use stdbool.h (C99) and the imported systemd
code is mostly gnu99 too (it's not clear to me, because I don't
find it precisely documented. Certainly it makes use of C99 features
too).

C99/gnu99 has some nice improvements that we no longer should miss
out. For example "flexible array members" or "variable declaration
in init-part of for loop".

It doesn't mean we have to use every obscure (badly supported?)
feature, it means we don't have to forgo features that are well
supported. C99 is 17 years old, I mean, really...

If somebody comes along and ports NM to non-gcc/clang, we can address
bugs about unsupported language features as they surface.
But let's not restrict us to some hypothetical compiler (or language
specification).

Also, NetworkManager is not ported on environment beside Linux.
We don't have to be so considerate about the required build environment.
Gcc is probably the most portable compiler out there. I doubt porting
NetworkManager to *BSD fails due to missing gnu99 features. And if that
causes issues, we should fix them after they happen in practice.
2016-11-10 09:34:39 +01:00
Thomas Haller
b8b68e212d build: disable warning "-Wformat-y2k"
https://bugzilla.gnome.org/show_bug.cgi?id=767207
2016-06-06 14:07:23 +02:00
Beniamino Galvani
b5daaf43bc build: configure.ac: always set -fno-strict-aliasing
We break the aliasing rules in the code, and thus the flag should
always be enabled to prevent wrong optimizations, even without
--enable-more-warnings.
2016-06-03 22:19:37 +02:00
Dan Williams
6725962f83 build: add -Wformat-nonliteral to --enable-more-warnings flags
New with gcc 6.0.
2016-06-03 11:05:05 -05:00
Lubomir Rintel
6d91c14b00 build: add macro to check the compiler flag support
Also, fold duplicate chunks together.
2016-05-18 20:53:51 +02:00
Lubomir Rintel
3b0dd0a55c trivial: rename compiler_warnings.m4 to compiler_options.m4
We'll use that for more compiler feature-checking macros.
2016-05-18 20:53:05 +02:00