How to disable warnings for system headers in Sun Studio 12

673 views Asked by At

We're in the middle of tidying up our codebase by (among other things) fixing all the compiler warnings.

The end goal is to turn on the flag that converts all warnings to errors. We've run into a slight snag with system and thirdparty headers. Some of the system headers cause the various compilers to emit warnings. Now obviously we can't go modifying system headers to fix those warnings.

With the intel compiler (and gcc) you simply use -isystem instead of -I when building up the include path to tell the compilers that headers in those dirs are system headers and it stops warning about them. Then it's a simple matter of turning on the -Werror flag.

We're also using Sun Studio 12, the flag -errwarn=%all should be the equivalent of -Werror, but I can't find a way to tell the compiler to ignore warnings in system / thirdparty headers. There is the -errhdr flag, but this doesn't seem to do what I want.

Does anyone know how to accomplish this with Sun Studio 12?

3

There are 3 answers

0
horsh On

Another option is to look at the warning tag using -errtags, and then switch off the particular warning with -erroff.

0
Mark Loeser On

Unfortunately (as far as I know), the errhdr flag is the best you can get. Be happy that you are using Sun Studio 12, since it was only just added in that release.

2
jon hanson On

Obviously, this isn't exactly what you want but in the absence of anything better you could wrap the offending includes in a #pragma error_messages block. E.g.

#pragma error_messages (on , tag .. tag)

#include <map>
// etc

#pragma error_messages (default , tag .. tag)

as described here. I don't currently have access to Solaris so I haven't tried this.