bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lib/dirfd.c: compiler warning: unused parameter


From: Bruno Haible
Subject: Re: lib/dirfd.c: compiler warning: unused parameter
Date: Thu, 04 May 2023 11:27:09 +0200

Thanks, this allows analysis.

What I see is:

1) The compilation command in config.log is

/usr/bin/gcc-12 -o conftest -Walloc-zero -Walloca -Wall -Wextra -Wformat=2 
-Wattribute-warning -Wdate-time -Wformat-security -Wfree-nonheap-object 
-Wimplicit-fallthrough=3 -Wmissing-noreturn -Wpedantic -Wstringop-overflow=4 
-Wredundant-decls -Wshadow=global -Wsuggest-attribute=noreturn -Wuninitialized 
-Wunused -Wunused-parameter -Wvla -fdiagnostics-generate-patch -freport-bug 
-fsanitize=undefined -fsanitize=bool -fsanitize=enum 
-fsanitize=signed-integer-overflow -fsanitize=integer-divide-by-zero,shift,null 
-fsanitize-undefined-trap-on-error -fno-sanitize=pointer-overflow 
-fsanitize=return -fsanitize=alignment,object-size,vptr,pointer-overflow -O2 
-fstack-protector-strong -fno-common -fstack-clash-protection -ftrapv 
-funsigned-char -fvar-tracking-assignments -ggdb3 -fsanitize=null 
-fsanitize=nonnull-attribute  -Wbad-function-cast -Wmissing-prototypes 
-Wold-style-definition -Wstrict-prototypes  -Wold-style-declaration  -std=gnu2x 
 -D_FORTIFY_SOURCE=2 -DGCC_LINT -DGNULIB_NO_VLA -D__USE_ISOC11   conftest.c

Two things are undefined behaviour here:

  - -funsigned-char : You are on a glibc system on x86_64; here the 'char' type
    is signed. Compiling code with -funsigned-char is thus undefined behaviour.

  - -D__USE_ISOC11 : You are not supposed to define macros that start with two
    underscores; these macros are owned by glibc. To specify which standards
    your code follows, use the -std=... option (which you did: -std=gnu2x)
    and you may define macros which start with a single underscore; they
    are explicitly listed in /usr/include/features.h.

The problem is here in config.log:

    conftest.c: In function 'main':
conftest.c:156:40: error: invalid use of incomplete typedef 'DIR'
  156 | DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;
      |                                        ^~

The test program has '#include <dirent.h>'; this is supposed to
define the DIR type. But the way your options interact with glibc,
this type is not present. As a consequence, both the test for d_fd
and the test for dd_fd failed, and the configure script activated
the fallback code (meant for systems from the 1980ies / 1990ies)
namely
  # define DIR_TO_FD(Dir_p) -1

So, that's what you need to fix:
  - Don't use -funsigned-char.
  - Don't use -D__USE_ISOC11.

Bruno






reply via email to

[Prev in Thread] Current Thread [Next in Thread]