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?
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
@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.
#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]|
}
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.
> 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.
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.