[cfe-dev] How to suppress a specific diagnostic?

Jordy Rose jediknil at belkadan.com
Thu Apr 26 18:00:19 PDT 2012

There are a couple ways to do this. If the warnings have individual flags (-Wfoo), you can disable them individually (-Wno-foo). This is probably what you want, and what existing users of Clang and GCC are familiar with.

If the warning you're interested in does /not/ have an individual flag (and most warnings mention which flag they're associated with in their diagnostic message), you could even file a bug, since we're working towards getting every warning under a flag. It's possible the warning /does/ have a flag, but doesn't say in the diagnostics, in which case you could see if it's in GCC's list of warnings. (Anything we both warn about, we try to make compatible with GCC, and sadly their warnings have better documentation.)

Even then, though, it might be better to use GCC's diagnostic pragmas to only disable the warnings around dubious practices A and B. Clang supports these pragmas; check out http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html for their usage.

Is that what you were looking for?

On Apr 26, 2012, at 20:38, Arthur O'Dwyer wrote:

> Okay, I feel like this ought to be a REALLY simple question, but I can't figure it out. If clang is giving me a spammy warning, how do I turn off that warning?
> I've got some autogenerated code (like, megabytes of it). This code contains some dubious practices, call them A and B; but I'm stipulating that practices A and B are actually perfectly fine in this specific instance. I need to tell clang to shut up about A and B; but at the same time, if other dubious practices such as C or D start showing up unbidden, I'd kind of like clang to catch those; i.e., I know I could just pass "-w", but that's a little blunt for this case.
> I'm coming from the world of EDG, where each diagnostic's severity level can be toggled independently (except for those diagnostics that indicate an uncompilable program). If I want to turn off warning #42, I just say --diag_suppress=42, and it's suppressed. But I can't figure out how to find out the unique identifiers associated with clang's warnings.
> To take a concrete example, let's say I have the following Objective-C code. I want to suppress the two bogus warnings about the @property (its getter and setter aren't going to be @synthesized anyway), but I still want to see the warning about division by zero. Or, alternatively, maybe I want to suppress the division-by-zero warning (maybe it's in unreachable code) but I still want to see the other warnings.
>   @interface Foo
>   @property Foo *foo;
>   @end
>   void f(int x) { x /= 0; }
> Is this just impossible with the current implementation of error handling in clang? If not, awesome! how do I do it?  Or, if so, are there any plans on the development roadmap to improve error handling to the point where users *can* toggle each diagnostic independently?
> Thanks,
> -Arthur
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list