Jonathan Wakely - Re: How do I find when the diagnostic pragmas first came into gcc? (original) (raw)

This is the mail archive of the gcc-help@gcc.gnu.orgmailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

On 12 January 2011 01:20, Patrick Horgan wrote:

On 01/11/2011 02:10 AM, Jonathan Wakely wrote:

I wrote this last week, which tames some of the ugliness:

#if ((GNUC * 100) + GNUC_MINOR)>= 405

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

This is great, and supports the use to turn warnings off wonderfully. ?From reading this I assume that 4.5 is the point at which the pragmas were able to be put at any scope instead of just file scope. ?Is this also true for

No, see my follow-up mail.

#pragma GCC system_header as well, that prior to 4.5 it had to be at file scope, but from 4.6 forward it can be at any scope?

As I said in another mail, I'm not sure if the system_header semantics have changed.

Also, can I steal, with attribution of course, GCC_DIAG_OFF/ON(x)?

Certainly.

Also is there an implementation define nesting limit to #pragma GCC diagnostic push as there is in the similar microsoft compiler #pragma warning push? ?(Their limit is about 50 I think). ?That seems like it would be plenty, but it's been hit in boost code that was doing tmp.

Also, what if there are too many pops? ?Is that an error, or ignored?

I don't know, you'll have to try.

Also did you consider making them so that you could use them like:

GCC_DIAG_OFF(sign-compare) ? if (a< ?b) { GCC_DIAG_ON(sign-compare) ? ? ? std::cout<< ?"a<b\n"; ? }

just to save the four keystrokes that would be common to all? ?Something like:

#define str(s) #s #define joinstr(x,y) str(x ## y)

#if ((GNUC * 100) + GNUC_MINOR) >= 405

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 joinstr(-W,x))

?define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)

else

?define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored joinstr(-W,x))

?define GCC_DIAG_ON(x) ?GCC_DIAG_PRAGMA(warning joinstr(-W,x))

endif

#else

define GCC_DIAG_OFF(x)

define GCC_DIAG_ON(x)

#endif

I know it's a little silly, but I get carried away wanting the compiler to do stuff for me.

I didn't do that, as my use case is actually much simpler, but it seems like a nice improvement.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]