Subject: [Boost-bugs] [Boost C++ Libraries] #3270: Ambiguous conversion, even though no conversion exists
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-07-16 14:29:57
#3270: Ambiguous conversion, even though no conversion exists
-------------------------------------------------+--------------------------
Reporter: Olaf Lenz <lenzo@â¦> | Owner: dgregor
Type: Bugs | Status: new
Milestone: Boost 1.40.0 | Component: function
Version: Boost 1.39.0 | Severity: Problem
Keywords: |
-------------------------------------------------+--------------------------
Cheers from Germany!
Look at the following code:
{{{
#include <boost/function.hpp>
struct A {};
struct B {
void f(const A &a) const {}
void f(boost::function< void () > a) {}
};
int main() {
A a;
B b;
b.f(a);
}
}}}
Compiling this, I get the error:
{{{
> g++ boosttest.cpp -o boosttest
boosttest.cpp: In function âint main()â:
boosttest.cpp:13: error: ISO C++ says that these are ambiguous, even
though the worst conversion for the first is better than the worst
conversion for the second:
boosttest.cpp:6: note: candidate 1: void B::f(const A&) const
boosttest.cpp:7: note: candidate 2: void B::f(boost::function<void ()(),
std::allocator<void> >)
}}}
When I define B::f() in the first version non-const, the program compiles
without any problems.
Usually, the problem in these cases is, that the conversion from an A to a
const A object is seen as an operation as bad as the conversion of the
object to another, therefore it is ambiguous and can be healed by using
"explicit" in the conversion operator of the other class. Unfortunately,
in this case, there does not even exist a conversion from "class A" to the
function type! To test that, just comment the first definition of B::f():
{{{
f(const A &a) const {}
}}}
compilation fails with:
{{{
> g++ boosttest.cpp -o boosttest
[clip]
boosttest.cpp:13: instantiated from here
/usr/include/boost/function/function_template.hpp:136: error: no match for
call to â(A) ()â
}}}
I think that this can be considered a bug. Or what else can I do in this
case?
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3270> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC