Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-01-26 13:40:21


While implementing operator== for boost::mem_fn, I found that the following
program, which I expected to print '1' six times, mysteriously outputs 1 0 1
1 0 1 under Comeau C++, causing all mem_fn equality tests to fail:

#include <iostream>

struct X
{
    int mf0_1() { return 0; }
    int mf0_2() { return 0; }
};

struct mf0
{
    typedef int (X::*F) ();
    F f_;

    explicit mf0(F f): f_(f) {}

    bool operator==(mf0 const & rhs) const
    {
        return f_ == rhs.f_;
    }

    bool operator!=(mf0 const & rhs) const
    {
        return f_ != rhs.f_;
    }
};

int main()
{
    std::cout << ( &X::mf0_1 == &X::mf0_1 ) << std::endl;
    std::cout << ( mf0(&X::mf0_1) == mf0(&X::mf0_1) ) << std::endl;
    std::cout << ( mf0(&X::mf0_1).f_ == mf0(&X::mf0_1).f_ ) << std::endl;

    std::cout << "--\n";

    std::cout << ( &X::mf0_1 != &X::mf0_2 ) << std::endl;
    std::cout << ( mf0(&X::mf0_1) != mf0(&X::mf0_2) ) << std::endl;
    std::cout << ( mf0(&X::mf0_1).f_ != mf0(&X::mf0_2).f_ ) << std::endl;
}

Output:

C:\Documents and Settings\pdimov\My Documents\Projects\testbed>como
testbed.cpp
Comeau C/C++ 4.3.0.1 (Aug 21 2002 15:45:32) for MS_WINDOWS_x86
Copyright 1988-2002 Comeau Computing. All rights reserved.
MODE:strict errors C++

C:\Documents and Settings\pdimov\My Documents\Projects\testbed>aout.exe
1
0
1

--
1
0
1
Is this a known issue with Comeau C++ 4.3? Or is there something wrong with
the code?
--
Peter Dimov
http://www.pdimov.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk