lmi
[Top][All Lists]
Advanced

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

Re: [lmi] PATCH: fix math_functions_test build with clang


From: Greg Chicares
Subject: Re: [lmi] PATCH: fix math_functions_test build with clang
Date: Sun, 22 May 2022 20:15:48 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0

On 5/22/22 19:07, Vadim Zeitlin wrote:
> On Sun, 22 May 2022 15:39:14 +0000 Greg Chicares <gchicares@sbcglobal.net> 
> wrote:
[...]
> GC> If "#pragma GCC' should be guarded with a test for LMI_GCC rather
> GC> than for __GNUC__

No, that's not the rule.

I had thought the rule was
  "#pragma GCC"   should be guarded by "#if defined __GNUC__", and
  "#pragma clang" should be guarded by "#if defined __clang__".
so that matching some regex such as
  "# *if *defined *__GCC__.*\n *# *pragma GCC"
would surely be an error ("\n" being EOL; or "\r" in vim IIRC).

Instead, the rule is more complicated:

(1) for gcc warnings that clang doesn't support:
     use "#pragma GCC" guarded by "#if defined LMI_GCC"
     that guard means __GNUC__ is defined and __clang__ is not;

(2) for clang warnings that gcc doesn't support:
     use "#pragma clang" guarded by "#if defined LMI_CLANG"
     that guard means __clang__ is defined and __GNUC__ is not;

(3) for gcc warnings that clang also supports:
     use "#pragma GCC" guarded by "#if defined __GNUC__"
     because clang defines __GNUC__ (I had remembered that) and
       clang respects "#pragma GCC" (I had forgotten that);
     but it doesn't disregard gcc-only warning pragmata.

The issue is that (3) usually DDRT, and when it does, it's
quite convenient; but when it doesn't, that can be confusing.

> GC> For example:
> GC> 
> GC>   $git grep -B3 'pragma GCC'
> GC>   bourn_cast.hpp-#if defined __GNUC__
> GC>   bourn_cast.hpp:#   pragma GCC diagnostic push
> GC>   bourn_cast.hpp:#   pragma GCC diagnostic ignored "-Wsign-compare"
> GC>   bourn_cast.hpp:#   pragma GCC diagnostic ignored "-Wsign-conversion"
> GC> 
> GC> Why isn't that a problem for clang, which AIUI defines __GNUC__ ?
> 
>  Because clang has the same warning options with the same meaning, so
> disabling them works (and is also helpful) for it too.

Okay, thanks.

> OTOH all versions of
> clang, even the most recent ones, define __GNUC__ as 4, so the pragmas
> guarded by the checks for a specific gcc version, such as the one for
> -Wbool-compare, in the same file, are not used with clang -- which is
> fortuitous because it would have resulted in a warning/error with it, as
> clang doesn't have this warning.

Oh. So we have not only cases {1,2,3} as above, but {1a,1b, ...}.
That would be an argument in favor of not relying on clang's
convenient but not complete support of gcc options. However...

>  So right now everything works as intended

...we write pragmata only as the need appears, so I'd be
reluctant to attempt sweeping revisions, especially because...

> but if you decide to remove all
> checks for gcc version (because we definitely don't support anything below
> 10 anyhow by now), it would break clang build and from this point of view
> it might be better to always check for LMI_GCC. But this would (probably, I
> didn't test it, but I'm almost sure it will) require adding pragmas for
> clang, inside LMI_CLANG checks, too, and many of them would duplicate the
> existing pragmas for gcc. So I'm not sure if you really want to do this.

I was thinking of accepting duplication as the price of clarity.
But I was hoping to do that through mechanical text processing
(deeming semantic differences not to exist), which won't work.
It's wiser to leave well enough alone.

The only optimal long-term strategy for #pragma is not to use it.


reply via email to

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