The code is following: (Coliru Code)
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <boost/logic/tribool.hpp>
struct B
{
boost::tribool boo;
void bug ()
{
bool tmp = indeterminate (boo);
std::cout << "tmp = " << std::boolalpha << tmp << "\n";
if (tmp && (boo = should_not_be_called ()) == false) {;}
}
bool should_not_be_called () const
{
std::cout << "BUG, wrong call\n";
abort ();
}
};
int main ()
{
B a;
a.bug ();
}
The output is
tmp = false
BUG, wrong call
bash: line 7: 14410 Aborted (core dumped) ./a.out
I cannot understand why should_not_be_called is called here. The tested compilers was gcc 4.9 and clang 3.6.
UPDATE:
I read the answers and changed the line with "if" to
if (tmp && (false == (boo = should_not_be_called ()))) {;}
(Coliru)
Now there are plain bool types on both sides of && operator, but I still got the same error. Why?