NetworkManager/src/libnm-std-aux
Thomas Haller 1c85bc5ead
std-aux: work around "-Wunused-but-set-variable" warning with clang in nm_auto()
We use the cleanup attribute heavily. It's useful for deferring
deallocation. For example, we have code like:

  gs_unref_object NMBluezManager *self_keep_alive = g_object_ref(self);

where we don't use the variable otherwise, except for owning (and
freeing) the reference. This already lead to a compiler warning about
unused variable, which we would workaround with

  _nm_unused gs_unref_object NMBluezManager *self_keep_alive = g_object_ref(self);

With clang 13.0.0~rc1-1.fc35, this got worse. Now for example also

    static inline void
    nm_strvarray_set_strv(GArray **array, const char *const *strv)
    {
        gs_unref_array GArray *array_old = NULL;

        array_old = g_steal_pointer(array);

        if (!strv || !strv[0])
            return;

        nm_strvarray_ensure(array);
        for (; strv[0]; strv++)
            nm_strvarray_add(*array, strv[0]);
    }

leads to a warning

    ./src/libnm-glib-aux/nm-shared-utils.h:3078:28: error: variable array_old set but not used [-Werror,-Wunused-but-set-variable]
        gs_unref_array GArray *array_old = NULL;
                               ^

This is really annoying. We don't want to plaster our code with _nm_unused,
because that might hide actual issues. But we also want to keep using this
pattern and need to avoid the warning.

A problem is also that GCC usually does not warn about truly unused
variables with cleanup attribute. Clang was very useful here to flag
such variables. But now clang warns about cases which are no bugs, which
is a problem. So this does loose some useful warnings. On the other hand,
a truly unused variable (with cleanup attribute) is ugly, but not an actual
problem.

Now, with clang 13, automatically mark nm_auto() variables as _nm_unused
as workaround.
2021-10-08 15:56:10 +02:00
..
c-list-util.c build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
c-list-util.h build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
meson.build build: remove "shared/" from include search path 2021-02-24 12:49:06 +01:00
nm-dbus-compat.h build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
nm-default-std.h clang-format: use "IndentPPDirectives:None" instead of "BeforeHash" 2021-07-09 08:49:06 +02:00
nm-linux-compat.h std-aux: add "libnm-std-aux/nm-linux-compat.h" header to avoid build errors 2021-09-08 15:27:17 +02:00
nm-networkmanager-compilation.h build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
nm-std-aux.h std-aux: work around "-Wunused-but-set-variable" warning with clang in nm_auto() 2021-10-08 15:56:10 +02:00
nm-std-utils.c build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
nm-std-utils.h std-aux: add NM_UTILS_GET_NEXT_REALLOC_SIZE_232 define 2021-04-12 16:46:00 +02:00
README.md all: add some README.md files describing the purpose of our sources 2021-08-19 17:51:11 +02:00
unaligned.h build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00

libnm-std-aux

A static helper library with general purpose helpers on top of standard C (C11).

As this has no additional dependencies, we should have all our C code use this internal helper library. It contains helpers that should be available (and used) everywhere where we write C.

Our C is gnu11, that is C11 or newer with some GCC-ism. The requirement is that it is supported by all complilers we care about (in pratice GCC and Clang).

Parts of this library are usually already included via the nm-default*.h headers.