[Bug c++/55908] New: Problem binding a const member function to a const object

sefi@s-e-f-i.de gcc-bugzilla@gcc.gnu.org
Tue Jan 8 13:17:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55908

             Bug #: 55908
           Summary: Problem binding a const member function to a const
                    object
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sefi@s-e-f-i.de


The following code fails to compile:

#include <functional>

typedef std::function<void (int) >func;

struct foo
{
        void f(int) const
        {
        }

        void g() const
        {
                func(std::bind(&foo::f, this, std::placeholders::_1));
        }
};

int main()
{
}

g++-4.8.0-alpha20130106 -std=c++11 test.cpp

test.cpp: In member function 'void foo::g() const':
test.cpp:14:55: error: no matching function for call to
'std::function<void(int)>::function(std::_Bind_helper<false, void
(foo::*)(int)const, const foo* const, const std::_Placeholder<1>&>::type)'
   func(std::bind(&foo::f, this, std::placeholders::_1));
                                                       ^
test.cpp:14:55: note: candidates are:
In file included from test.cpp:1:0:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2252:2:
note: template<class _Functor, class> std::function<_Res(_ArgTypes
...)>::function(_Functor)
  function(_Functor);
  ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2252:2:
note:   template argument deduction/substitution failed:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2227:7:
note: std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes
...)>&&) [with _Res = void; _ArgTypes = {int}]
       function(function&& __x) : _Function_base()
       ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2227:7:
note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void
(foo::*)(int)const, const foo* const, const std::_Placeholder<1>&>::type {aka
std::_Bind<std::_Mem_fn<void (foo::*)(int)const>(const foo*,
std::_Placeholder<1>)>}' to 'std::function<void(int)>&&'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2430:5:
note: std::function<_Res(_ArgTypes ...)>::function(const
std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {int}]
     function<_Res(_ArgTypes...)>::
     ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2430:5:
note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void
(foo::*)(int)const, const foo* const, const std::_Placeholder<1>&>::type {aka
std::_Bind<std::_Mem_fn<void (foo::*)(int)const>(const foo*,
std::_Placeholder<1>)>}' to 'const std::function<void(int)>&'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2207:7:
note: std::function<_Res(_ArgTypes ...)>::function(std::nullptr_t) [with _Res =
void; _ArgTypes = {int}; std::nullptr_t = std::nullptr_t]
       function(nullptr_t) noexcept
       ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2207:7:
note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void
(foo::*)(int)const, const foo* const, const std::_Placeholder<1>&>::type {aka
std::_Bind<std::_Mem_fn<void (foo::*)(int)const>(const foo*,
std::_Placeholder<1>)>}' to 'std::nullptr_t'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2200:7:
note: std::function<_Res(_ArgTypes ...)>::function() [with _Res = void;
_ArgTypes = {int}]
       function() noexcept
       ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0-alpha20130106/include/g++-v4/functional:2200:7:
note:   candidate expects 0 arguments, 1 provided


The problem goes away if the int parameter is taken out, or if g() is not
const.
gcc-4.7.2 accepts the test case.



More information about the Gcc-bugs mailing list