Opened 10 years ago

Closed 10 years ago

#7964 closed Bugs (fixed)

'boost::system::error_code::unspecified_bool_type' : forcing value to bool 'true' or 'false' (performance warning)

Reported by: szx <szx@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: system
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

I'm getting the following warning on MSVC 11.0 when using boost::system::error_code in an if() statement:

warning C4800: 'boost::system::error_code::unspecified_bool_type' : forcing value to bool 'true' or 'false' (performance warning)

Change History (3)

comment:1 by viboes, 10 years ago

Please, could you add a little bit more context on the compiler error?

comment:2 by szx <szx@…>, 10 years ago

Strangely enough it seems to only appear in lambda functions because this code compiles without warnings:

#include <boost/system/error_code.hpp>

void f(const boost::system::error_code &error) {

if (error) {}

}

int main() {

f(boost::system::error_code());

}

while the following one

#include <boost/system/error_code.hpp> int main() {

auto lambda = [](const boost::system::error_code &error) {

if (error) {}

};

}

results in

test.cpp(6): warning C4800: 'boost::system::error_code::unspecified_bool_type' : forcing value to bool 'true' or 'false' (performance warning)

It's probably a compiler bug then I would guess.

comment:3 by Beman Dawes, 10 years ago

Resolution: fixed
Status: newclosed

I was able to reproduce this warning, but I don't see any short term fix. Seems like the warning is an artifact of the unspecified_bool_type idiom.

The longer term fix is for boost.system to use the C++11 explicit conversion operator, as is specified for the standard library's version of these classes. That change has now been made (changeset 83210) for compilers that support the C++11 explicit conversion operator, such as late model gcc and VC++ November 2012 CTP. On that basis, the issue is being closed.

Thanks,

--Beman

Note: See TracTickets for help on using tickets.