Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-09 Thread Sébastien Hinderer
Many thanks Russ for the helpful response, and for the -Weverything
trick, I'll give it a try!

And thanks to Paul, too!

Sébastien.



Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-08 Thread Paul Eggert

On 2/7/21 11:46 PM, Sébastien Hinderer wrote:

Did you notice important changes in the supported warnings between
different versions of the same compiler?

Are there many warnings in common between (at least one version of)
clang and (at least one version of) gcc, actually?


The short answers to those two questions are "yes" and "yes".

I don't know of anybody who's come up with a comprehensive list of which 
compiler versions support which warnings correctly. Such a list would be 
tricky to do, as some warnings imply others, some warnings are 
language-dependent, and the warning dependencies can also change from 
version to version. At Gnulib we gave up trying to keep track of all the 
warnings (even though we were just doing GCC, not clang) and are 
currently using only the warnings listed here:


https://git.savannah.gnu.org/cgit/gnulib.git/tree/m4/manywarnings.m4
https://git.savannah.gnu.org/cgit/gnulib.git/tree/m4/manywarnings-c++.m4

with further documentation here:

https://git.savannah.gnu.org/cgit/gnulib.git/tree/build-aux/gcc-warning.spec



Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-08 Thread Russ Allbery
Sébastien Hinderer  writes:

> Did you notice important changes in the supported warnings between
> different versions of the same compiler?

Yes, mostly that new version of the compiler add new warnings, and
sometimes new warning flags.  I probe for whether the compiler supports
each flag during Autoconf, and periodically I review the release notes of
the two compilers and add new interesting warning flags.

> Are there many warnings in common between (at least one version of)
> clang and (at least one version of) gcc, actually?

I think there is some overlap between the flags (-W -Wall are the same,
for instance), although I didn't investigate in detail because I started
down the -Weverything with a blacklist path with Clang early on and GCC
doesn't (so far as I know) support that.

For the record, apparently the Clang folks don't really want people to use
-Weverything.  I still do anyway, for maintainer builds, and have not had
any real problems with that (and have been grateful to pick up new
warnings automatically), but it shouldn't be a default.

-- 
Russ Allbery (ea...@eyrie.org) 



Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-08 Thread Sébastien Hinderer
Many thanks for yoru suggestion, Russ.

David's approach makes sense to me but yours too.

Did you notice important changes in the supported warnings between
different versions of the same compiler?

Are there many warnings in common between (at least one version of)
clang and (at least one version of) gcc, actually?

Thanks,

Sébastien.



Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-05 Thread Russ Allbery
Sébastien Hinderer  writes:

> It seems AC_PROG_CC wrongly believes clang is gcc and that may cause
> problems when clang is passed a warning which is only supposrted by gcc,
> as is the case e.g. for -Wno-stringop-truncation.

> Is there a recommended way to determine for sure from a configure script
> whether the detected C compiler is clang or gcc?

You can test each individual flag, but I found that tedious and irritating
because I wanted to write a list of warning flags for Clang based on its
manual and a list of warning flags for GCC based on its manual.

Rather than try to detect GCC, I reversed the logic and tried to detect
Clang instead, which seems to be somewhat easier.

dnl Source used by RRA_PROG_CC_CLANG.
AC_DEFUN([_RRA_PROG_CC_CLANG_SOURCE], [[
#if ! __clang__
#error
#endif
]])

AC_DEFUN([RRA_PROG_CC_CLANG],
[AC_CACHE_CHECK([if the compiler is Clang], [rra_cv_prog_cc_clang],
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_RRA_PROG_CC_CLANG_SOURCE])],
[rra_cv_prog_cc_clang=yes],
[rra_cv_prog_cc_clang=no])])
 AS_IF([test x"$rra_cv_prog_cc_clang" = xyes], [CLANG=yes])])

-- 
Russ Allbery (ea...@eyrie.org) 



Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-05 Thread David A . Wheeler
 On Feb 5, 2021, at 9:51 AM, Todd C. Miller 
 wrote:
 On Fri, 05 Feb 2021 15:42:28 +0100, =?utf-8?Q?S=C3=A9bastien?=
 Hinderer wrote:

 It seems AC_PROG_CC wrongly believes clang is gcc and that may cause
 problems
 when clang is passed a warning which is only supposrted by gcc, as
 is
 the case e.g. for -Wno-stringop-truncation.

 clang also defines __GNUC__ and the related defines, which is why
 it is identified as gcc.

 Is there a recommended way to determine for sure from a configure
 script
 whether the detected C compiler is clang or gcc?

   I would *discourage* trying to figure out if a C compiler is gcc or
   clang.
   Instead, create separate detectors for whatever you’re looking for.
   The gcc & clang groups coordinate with each other; they try to provide
   the same
   flags & API for the same functionality, and occasionally copy from each
   other.
   So trying to detect “do this if GCC” is generally wrong; clang may have
   that interface & functionality
   when someone compiles the code.
   --- David A. Wheeler


Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-05 Thread Sébastien Hinderer
Many thanks Todd for your helpful response!

Sébastien.



Re: AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-05 Thread Todd C. Miller
On Fri, 05 Feb 2021 15:42:28 +0100, =?utf-8?Q?S=C3=A9bastien?= Hinderer wrote:

> It seems AC_PROG_CC wrongly believes clang is gcc and that may cause problems
> when clang is passed a warning which is only supposrted by gcc, as is
> the case e.g. for -Wno-stringop-truncation.

clang also defines __GNUC__ and the related defines, which is why
it is identified as gcc.

> Is there a recommended way to determine for sure from a configure script
> whether the detected C compiler is clang or gcc?

You need to test whether the specific warning flag is supported by
the compiler.  These flags also vary based on gcc version so this
is not a problem specific to clang.  I like to use AX_CHECK_COMPILE_FLAG
for this, see:

http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html

 - todd



AC_PROG_CC: how to distinguish clnag from gcc?

2021-02-05 Thread Sébastien Hinderer
Dear all,

It seems AC_PROG_CC wrongly believes clang is gcc and that may cause problems
when clang is passed a warning which is only supposrted by gcc, as is
the case e.g. for -Wno-stringop-truncation.

Is there a recommended way to determine for sure from a configure script
whether the detected C compiler is clang or gcc?

Thanks,

Sébastien.