Can anyone tell me how to suppress the following warning message which is generated by Boost.Log and GCC 4.4.7? My project is built in C++11 mode (with -std=c++0x
in GCC 4.4.7).
src/Logger.cc:7: warning: missing initializer for member ‘boost::log::v2_mt_posix::expressions::attribute_keyword<tag::severity, boost::phoenix::actor>::proto_expr_’
where src/Logger.cc
is the source file of my logging class which is a wrapper of Boost.Log. Line 7 uses one of Boost.Log macros as follows. Logger::ESeverityLevel
is an enum defined in Logger.h
.
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", Logger::ESeverityLevel)
This macro can be expanded as follows.
namespace tag {\
struct severity :\
public ::boost::log::expressions::keyword_descriptor\
{\
typedef Logger::ESeverityLevel value_type;\
static ::boost::log::attribute_name get_name() { return ::boost::log::attribute_name("Severity"); }\
};\
}\
typedef ::boost::log::expressions::attribute_keyword< tag::severity > severity_type; const severity_type severity = {};
It looks that the initialization of severity_type
makes this warning, while it is valid with Clang (Apple LLVM version 6.0).
An official example code of this macro can be found at http://theboostcpplibraries.com/boost.log#ex.log_05
One approach is to disable the warning in GCC using it's built-in #pragma
s, e.g.
#pragma GCC diagnostic push // Save the current warning state
#pragma GCC diagnostic ignored "-Wmissing-field-initializers" // Disable the warning you're getting
...
// offending code
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", Logger::ESeverityLevel)
...
#pragma GCC diagnostic pop // Restore previous default behaviour
You can also disable this behaviour at the command line using the -Wno-missing-field-initializers
.