On Wed, Sep 06, 2023 at 03:08:33PM -0700, Mike Fulton wrote: > Hello, > > The m4 dev line ( git://git.savannah.gnu.org/m4.git ) > has the following code: > > ``` > #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) > # pragma GCC diagnostic push > # pragma GCC diagnostic ignored "-Wformat-nonliteral" > #endif > ```
That expression appears to be designed to reject gcc 3.5 and older, while accepting 3.6 and newer. I also wonder if modern gnulib provides a better way to test things than just open-coding it (as Bruno has done a lot of work testing features of newer compilers). This may be one case where ignoring the diagnostic for older builds is desirable - there comes a point where you can't please both old and new compilers simultaneously, but the target that should be warning-free is the newer compiler. That is, maybe it's time to just rewrite the check to something as simple as #if 8 <= __GNUC__ (that is, only add the pragmas on a much newer, albeit arbitrary, point in time)? Conversely, I see that m4 uses gnulib's lib/c-stack.c, which also has: /* Pacify GCC 9.3.1, which otherwise would complain about segv_handler. */ # if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" # endif so it's not like m4 is doing anything radically different from gnulib when it comes to pragmas for ignoring certain diagnostics; but thd difference may be which diagnostic is being ignored. > > This produces an error on the clang compiler I am using on z/OS, which is > at 4.2 with the xasprintf code that follows, e.g. > > ``` > str = xasprintf (fstart, width, ARG_INT(argc, argv)); > ``` > > If I change the check to: > > ``` > #if 4 < __GNUC__ + (2 <= __GNUC_MINOR__) > # pragma GCC diagnostic push > # pragma GCC diagnostic ignored "-Wformat-nonliteral" > #endif > ``` > > all is good - it compiles clean. The question is whether the check for 6 is > too high or if the clang compiler on z/OS has a bug (or something else)? What does clang claim to be? That is, what do you get for print '__GNUC__ __GNUC_MINOR__' | clang -E - | tail -n1 and what is the actual compiler error you got when the build failed on the original source? > I haven't been able to determine what level of gcc provides this diagnostic. > > thanks, mike -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org