You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/home/anton/catkin_ws/src/cisst-saw/cisst/cisstCommon/tests/cmnLogLoDTest.cpp:100:12: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses]
There were 4 of these in cisst, 2 in cisstMultiTask, 2 in cisstRobot.
Unfortunately adding braces in the macro doesn't solve the issue. The macro is used like this:
CMN_LOG(level) << "some text" << std::end;
With the braces, this expends as:
{ if (condition) outputStream << } "some text" << std::endl;
which won't compile.
We can change the macro a bit to avoid the bug (I think?) but still triggers the gcc warning:
// current logic
#definelog(level) \\
if (needToLog(level)) outputStream <<
// new logic
#definelog(level) \\
if (!needToLog(level)) ; else outputStream <<
This is a bit better but programmers should still use braces to avoid the gcc warnings. Testing in branch bug-log: 2ddc476
I tested compilation and unit test for macro CMN_LOG on Windows/VS2013, MacOS clang, Linux gcc and it seems to work. I was expecting some warning because of the no-op before the else but all compilers seem fine with it.
The following code does not produce the expected result:
This appears to be due to the macro used to define
CMN_LOG
(note thatCMN_LOG_RUN_VERBOSE
just callsCMN_LOG
with a specifiedlod
):Simplifying the above,
CMN_LOG(lod)
essentially expands to the following:Thus, the original code is compiled as follows, where the
else
is indented to better indicate the problem:I believe the fix would be to put braces around the entire
CMN_LOG
macro, e.g.:The text was updated successfully, but these errors were encountered: