On Mon, 04 Jan 2021 20:20:58 -0000, Karl Palsson wrote:
> This is akin to the classic problem of logging macros turning off
> code. You need to introduce an extra variable for the assert to
> check. (If you want to keep going down this path)

Thank you very much for your 'junk' code :) I've tested
that introducing an extra variables sometimes causes
another unused warning, which is unfortunately treated
as error by gcc. Sorry for proposing such problematic patch!

#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

static int k;

void call_it_safe(void) {
        int ret;
        assert(++k > 0);
        errno = 0;
        ret = chown("/non-exist-directory", 1000, 1002);
        assert(ret == 0);
        fprintf(stderr, "errno: %d\n", errno);
        fflush(stderr);
}
gcc -Wall -Werror -DNDEBUG -o hate_ndebug hate.c
hate.c: In function ‘call_it_safe’:
hate.c:10:6: error: variable ‘ret’ set but not used 
[-Werror=unused-but-set-variable]
   10 |  int ret;
      |      ^~~
cc1: all warnings being treated as errors

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to