gcc: How to fully ignore warnings from libraries

Dec 30, 2013 at 12:34am
I know I can use -isystem path to mark a path as containing system headers which shouldn't be included when generating warnings, and this works, but it doesn't work when the warnings are generated by instantiating templates from the library in my source code. Is there any way to ignore these template-instantiation-generated warnings too?
Dec 30, 2013 at 2:13am
Last edited on Dec 30, 2013 at 2:28am
Dec 30, 2013 at 3:31am
Try to build ChessPlusPlus at this commit:
https://github.com/LB--/ChessPlusPlus/commit/0110ad376032fba1f40df11a33237f3ce0fdeabd
With CMAKE_CXX_FLAGS="-Wzero-as-null-pointer-constant -Werror -Wfatal-errors"

I get this warning:
In file included from C:/Users/Nicholas/Desktop/GitHub/ChessPlusPlus/src/config/
BoardConfig.hpp:4:0,
                 from C:\Users\Nicholas\Desktop\GitHub\ChessPlusPlus\src\board\B
oard.hpp:4,
                 from C:\Users\Nicholas\Desktop\GitHub\ChessPlusPlus\src\board\B
oard.cpp:1:
C:/Users/Nicholas/Desktop/GitHub/ChessPlusPlus/src/config/Configuration.hpp: In
constructor 'boost::filesystem::path::path(const Source&, typename boost::enable
_if<boost::filesystem::path_traits::is_pathable<typename boost::decay<Source>::t
ype> >::type*) [with Source = std::basic_string<char>; typename boost::enable_if
<boost::filesystem::path_traits::is_pathable<typename boost::decay<Source>::type
> >::type = void]':
C:/Users/Nicholas/Desktop/GitHub/ChessPlusPlus/src/config/Configuration.hpp:30:5
9: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
                 if(boost::filesystem::extension(configFile) != ".json")
                                                           ^
compilation terminated due to -Wfatal-errors.
cc1plus.exe: all warnings being treated as errors
Last edited on Dec 30, 2013 at 3:35am
Dec 30, 2013 at 5:10am
closed account (Dy7SLyTq)
well first dont use -Werror as this turns all warnings into errors and then -w turns off warnings
Dec 30, 2013 at 5:25am
@DTSCode, I think that @L B wants to build with warnings (as should be done), and is using -Werror and -Wfatal-errors to be able to fix a warning upon receiving it.

@L B, I don't think there is a way, though I'm not knowledgeable about GCC to be able to say for certain.
Dec 30, 2013 at 5:27am
closed account (Dy7SLyTq)
im sorry i misunderstood. are you asking how to turn off one specific kind of warning?
Dec 30, 2013 at 5:32am
I am asking how to turn off warnings that come from system header template instantiations.
Dec 30, 2013 at 5:40am
A quick look inside a system header reveals:

#pragma GCC system_header

http://gcc.gnu.org/onlinedocs/cpp/System-Headers.html#System-Headers
Last edited on Dec 30, 2013 at 5:42am
Dec 30, 2013 at 6:19am
I can't modify the boost and SFML headers, unfortunately.
Dec 30, 2013 at 6:22am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma GCC diagnostic push
// save the current state for diagnostics

#pragma GCC diagnostic ignored "-Wunused-parameter"
// turn off diagnostic for "-Wunused-parameter"  

#include "some_header.h"

// note: some_header.h contains: 
// template < typename T > int foo( T arg_foo ) { return 0 ; }

#pragma GCC diagnostic pop
// restores the saved state for diagnostics (diagnostics as specified in the command line)  

template < typename T > int bar( T arg_bar ) { return 0 ; }

// compiled with: -std=c++11 -O2 -Wall -Wextra -pedantic-errors

int main()
{
    foo(100) ; 

    bar(100) ; // *** warning: unused parameter 'arg_bar' [-Wunused-parameter]|
}

http://coliru.stacked-crooked.com/a/8e80ce10ba75b107


EDIT:
====

Boost warnings guidelines do not require anything more than clean for -Wall -pedantic
https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines

Boost Filesystem is clean for -Wall -Wextra -pedantic
(but probaly not for -Wzero-as-null-pointer-constant)
https://svn.boost.org/trac/boost/wiki/WarningFixes
Last edited on Dec 30, 2013 at 6:33am
Dec 30, 2013 at 6:25am
I think there is still a misunderstanding - the warning is not generated in the header, it is generated in the code that uses a template when the template gets instantiated. I know this didn't happen before but I can't figure out what changed.
Dec 30, 2013 at 7:23am
> I think there is still a misunderstanding - the warning is not generated in the header,
> it is generated in the code that uses a template when the template gets instantiated.

The misunderstanding will go away if you care to read the snippet.

foo(100) ; is the instantiation of the template from the header; no diagnostic is generated for that.
#pragma GCC diagnostic ignored "-Wunused-parameter" applies when foo(int) is instantiated.

bar(100) ; is the instantiation of the template without #pragma GCC diagnostic ignored "-Wunused-parameter" ; it is the one that generates a diagnostic.
Dec 30, 2013 at 7:25am
I think there is something wrong with my environment because I get a warning for both lines. Even if it did work it would be quite a pain because I just want to change the compiler flags when building ChessPlusPlus.

I will mess around with my environment and see if I can fix it.
Last edited on Dec 30, 2013 at 7:27am
Dec 30, 2013 at 7:39am
> I think there is something wrong with my environment because I get a warning for both lines.

Hmm.. AFAIK, the pragma would override the diagnostic settings of the environment.


> it would be quite a pain because I just want to change the compiler flags when building ChessPlusPlus.

This would be required just in the code for ChessPlusPlus:

1
2
3
4
5
6
7
8
9
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
// other #pragma GCC diagnostic ignored as required 

// #include boost headers

#pragma GCC diagnostic pop

// use boost headers 


Does that still generate a diagnostic for -Wzero-as-null-pointer-constant?
Topic archived. No new replies allowed.