Re: How do I find when the diagnostic pragmas first came into gcc?

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

 



On 11 January 2011 10:10, Jonathan Wakely wrote:
>
> I wrote this last week, which tames some of the ugliness:
>
> #if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 405

This check could probably be 402 not 405
(I don't have my custom warnings in any build older than 4.5, which is
why I checked 4.5)

> # define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
> # define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
> # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
> #  define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
>     GCC_DIAG_PRAGMA(ignored x)
> #  define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
> # else
> #  define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored x)
> #  define GCC_DIAG_ON(x)  GCC_DIAG_PRAGMA(warning x)
> # endif
> #else
> # define GCC_DIAG_OFF(x)
> # define GCC_DIAG_ON(x)
> #endif
>
> That gives convenient macros which are used like so:
>
> GCC_DIAG_OFF("-Wsign-compare")
>   if (a < b) {
> GCC_DIAG_ON("-Wsign-compare")
>       std::cout << "a<b\n";
>   }

Oops, this example assumes the pragma can occur at function scope
which is only true for 4.6, so if you do want to make the macros work
with 4.2 to 4.5 then they should only be used at namespace scope.

Another option would be to have a file-scope GCC_DIAG_OFF_FOO for GCC
4.2 - 4.5 (which expands to nothing for 4.6+) and a finer-grained
GCC_DIAG_OFF_BAR for GCC 4.6+ (which expands to nothing for pre-4.6)
but then library authors have to maintain two OFF/ON pairs for each
warning they want to disable.

If you only care about supporting 4.6+ then life is easier and
GCC_DIAG_ON doesn't even need an argument (as it just pops the last
OFF)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux