SunStudio C++ compiler pragma to disable warnings?

2020-04-11 18:03发布

The STLport bundled with the SunStudio11 generates alot of warnings. I beleive most compilers have a way to disable warnings from certain source files, like this:

Sun C

#pragma error_messages off

#include <header.h>
// ...

#pragma error_messages on

gcc

#pragma warning(push, 0)        

#include <header.h>
// ...

#pragma warning(pop)

How do you do this in the SunStudio C++ compiler? (btw, the sunstudio C pragmas don't work in sunstudio C++)

4条回答
Anthone
2楼-- · 2020-04-11 18:44

In SunStudio 12, the #pragma error_messages work as documented in the C users manual.

You can see the tags with the -errtags=yes option, and use it like this:

// Disable badargtypel2w:
//     String literal converted to char* in formal argument
#pragma error_messages (off, badargtypel2w )

and then compile with CC (the C++ compiler).

查看更多
叼着烟拽天下
3楼-- · 2020-04-11 18:48

add -w to your $CC or whatever var you use.

查看更多
甜甜的少女心
4楼-- · 2020-04-11 18:57

Can't help with turning the warnings off, but when I last looked at SunStudio, it shipped with two STLs - an older one for backward compatibility with earlier compiler versions and STLport. Might be worth checking if you're using STLport before trying to trying to turn off the warnings.

查看更多
不美不萌又怎样
5楼-- · 2020-04-11 18:59

If you'd rather use a command line option than #pragmas, a simple answer is that you can use -erroff=%all on your compile line.

You can suppress specific warning messages with -erroff=%tag

You can print out the tags for the warning messages by adding -errtags to your compile line. You can then define a set of comma-separated values for -erroff that suppress just those tags.

See http://docs.oracle.com/cd/E19205-01/820-7599/bkapa/index.html for more info.

Note that Sun Studio 12 update 1 is now available, and I'm referencing the SS12u1 doc here.

查看更多
登录 后发表回答