Opened 18 years ago

Closed 18 years ago

#339 closed Bugs (Fixed)

Tribool: strange results on I/O

Reported by: ethouris327 Owned by: Douglas Gregor
Milestone: Component: None
Version: None Severity:
Keywords: Cc:

Description

Please look at the code below:

#include <iostream>
#include <boost/logic/tribool.hpp>
using namespace std;
using namespace boost::logic;

#define PRINTEXP( exp ) print_exp( #exp, exp )

inline void print_exp( const char* name, tribool expr )
{
cout << name << ": " << boolalpha << expr << endl;
}

int main( int argc, char** argv )
{
	cout << true << endl;
	cout << false << endl;
	cout << indeterminate << endl;

	const tribool yes = true;
	const tribool no = false;
	const tribool maybe = indeterminate;

	PRINTEXP( yes );
	PRINTEXP( no );
	PRINTEXP( maybe );

	return 0;
}


According to the documentation, the result should be:

1
0
2
yes: true
no: false
maybe: indeterminate

However the result is:
1
0
1
yes: true
no: false
maybe: false


Of course, there is a warning when compiling:

lite-3bool.cc:20: warning: the address of `bool 
   boost::logic::indeterminate(boost::logic::tribool, 
   boost::logic::detail::indeterminate_t)', will always be 
`true'

which excuses the "1" for indeterminate, however also 
proves that no `ostream& << tribool' is defined (or it's 
somehow not seen).


> uname -a
CYGWIN_NT-5.1 hostname 1.5.12(0.116/4/2) 2004-11-
10 08:34 i686 unknown unknown Cygwin

> g++ -v
...
Thread model: posix
gcc version 3.3.3 (cygwin special)


Change History (1)

comment:1 by Douglas Gregor, 18 years ago

Status: assignedclosed
Logged In: YES 
user_id=249098

There are two issues here, one in the example program and one in the 
Tribool code. 

1) The warning is telling is that it really is converting the address of 
"indeterminate" (which is a function, not actually a "tribool") to a boolean 
value, then using the ostream << overload for bool. This is a bug in Tribool 
which I've just fixed.

2) The "maybe: false" is actually a bug in the sample program, which does 
not #include <boost/logic/tribool_io.hpp> and therefore doesn't actually get 
any of the tribool I/O operations.
Note: See TracTickets for help on using tickets.