I am using log4cplus, and my misra-checks for something as innocent-looking as
LOG4CPLUS_INFO(
logger,
std::string("ABC") + std::string("DEF"));
yield (among others) The underlying type of `0L` is implicitly reduced from `8-bit signed char` to {code{bool}}.. This happens also when I put the respective literals rather than wrapping them inside string. I wonder how to fix this. Or, more generally put, how would you concatenate several log messages and yet keep MISRA-checks happy?
I had a look at
LOG4CPLUS_INFOand that is a macro defined as:and
LOG4CPLUS_MACRO_BODYis defined as:and so your MISRA checker will be checking the invocation of the macro. And MISRA likes
ifstatements to be defined explicitly in terms ofboole.g. rather thanif(node)it likesif(node!=nullptr)and I think it may have an issue with the last line:As
0is being implicitly cast tobool. You should see if you get the same warning by adding a simpledo{}while(0);loop to your code and run your checker again.And if you want a MISRA safe way of logging, I would avoid the use of macros. You can make a simple logging class with a
std::ofstreamand astd::mutexand keep it in namespace scope defined as an extern in your header file.