1

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?

Glen
  • 21,816
  • 3
  • 61
  • 76

3 Answers3

2

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.

jon hanson
  • 8,722
  • 2
  • 37
  • 61
  • yeah, I was hoping to be able to avoid that, but I may have no choice. It may get messy as I've also got the same problem with HP's aCC compiler. – Glen Jan 26 '11 at 17:46
  • I guess you could collect these header includes into a single file per platform. I.e. take the above code and move to a headers_solaris.h file. Then have another one for HP. Finally have a headers.h which then includes the appropriate platform-specific headers file. Still messy though. – jon hanson Jan 28 '11 at 08:37
1

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

Alexander Gorshenev
  • 2,769
  • 18
  • 33
0

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.

Mark Loeser
  • 17,657
  • 2
  • 26
  • 34