Boost 1.55, MSVC express 2012. Wrong expression evaluation with tribool. It works correct only when I specify tribool(false) explicitly.
Moral of the story: compiler chooses TYPES based on VALUES.
auto a = 0? indeterminate : false; // type function pointer
auto b = 0? indeterminate : true; // type bool
Output:
- indet : 1? indeterminate : false
- indet : 0? indeterminate : false
- true : 1? indeterminate : true
- true : 0? indeterminate : true
- indet : 1? indeterminate : tribool(false)
- false : 0? indeterminate : tribool(false)
- indet : 1? indeterminate : tribool(true)
- true : 0? indeterminate : tribool(true)
Source code:
#include <iostream>
#include <boost/logic/tribool.hpp>
using namespace boost;
void test_tribool( const tribool& v, const char* name )
{
const char* s;
if ( v )
s = "true";
else if ( !v )
s = "false";
else
s = "indet";
std::cout << s << "\t: " << name << std::endl;
}
#define TEST_TRIBOOL( ... ) test_tribool( (__VA_ARGS__), #__VA_ARGS__ );
int main(int argc, char** argv)
{
TEST_TRIBOOL( 1? indeterminate : false );
TEST_TRIBOOL( 0? indeterminate : false );
// warning C4305: ':' : truncation from 'bool (__cdecl *)(boost::logic::tribool,boost::logic::detail::indeterminate_t)' to 'bool'
TEST_TRIBOOL( 1? indeterminate : true );
// warning C4305: ':' : truncation from 'bool (__cdecl *)(boost::logic::tribool,boost::logic::detail::indeterminate_t)' to 'bool'
TEST_TRIBOOL( 0? indeterminate : true );
TEST_TRIBOOL( 1? indeterminate : tribool(false) );
TEST_TRIBOOL( 0? indeterminate : tribool(false) );
TEST_TRIBOOL( 1? indeterminate : tribool(true) );
TEST_TRIBOOL( 0? indeterminate : tribool(true) );
return 0;
}