> -----Original Message-----
> From: Martin Sebor [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 21, 2006 2:29 AM
> To: [email protected]
> Subject: Re: VC7 fails to compile conv_to_bool == false
>
> It would be good to have a test case for the compiler bug so
> we can figure out if we can work around it and how (since
> MSVC 7.0 has been superseded by not just one but two more
> recent versions I wouldn't spend too much time on narrowing
> it down to a test case if it's hard; we can simply disable
> those tests for this compiler).
struct conv_to_bool
{
static conv_to_bool make (bool val) {
return conv_to_bool (val);
}
typedef bool conv_to_bool::*UniquePtr;
operator UniquePtr () const {
return val_ ? &conv_to_bool::val_ : UniquePtr (0);
}
private:
conv_to_bool (bool val): val_ (val) { }
void operator= (conv_to_bool); // not Assignable
void operator!() const; // not defined
bool val_;
};
conv_to_bool ctb = conv_to_bool::make (true);
The place of fail is expression
ctb == false
This expression is present in algotihm find_if ("__pred (*__first) ==
false") and others as well.
template <class _InputIter, class _Predicate>
inline _InputIter
find_if (_InputIter __first, _InputIter __last, _Predicate __pred)
{
_RWSTD_ASSERT_RANGE (__first, __last);
for (; !(__first == __last) && __pred (*__first) == false;
++__first);
return __first;
}
This expression fails (the compiler tries find matching
operator==(type1, type2) and not tries to
convert conv_to_bool::UniquePtr to bool and use operator(bool, bool)):
if (ctb == false)
but theese expressions are ok:
If (ctb)
If (!ctb)
If (bool (ctb) == false)
So for successful compiling of the algorithms tests we can:
1. define conv_to_bool::UniquePtr as const void* (only for VC7 using
#ifdef/#else/#endif)
2. replace the expressions like "__pred (*__first) == false" to "bool
(__pred (*__first)) == false"
or to "!(__pred (*__first))" (this variant is worse because of possibly
defined custom operator!())
Farid.