This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to get more info about 'bad_function_call' ?


On 27 January 2015 at 16:56, Linda A. Walsh <gcc@tlinx.org> wrote:
> Jonathan Wakely wrote:
>>
>>
>> By doing exactly that. Check if the std::function you're calling is
>> valid, e.g. if (f) or if (f == nullptr) or if (!!f) or whatever floats
>> your boat.
>>
>
> ----
> I tried that --- nothing converts it to a printable.

Not in the debugger, put if (f != nullptr) in the C++ source code!


> What I see in my prog is:
>    function<void (void) > work{};
>
> And 'work' is "valid"** -- it points into a lib function and it is inside
> the c++
> function that it is determined to be invalid.

Just humour me and try assert( work != nullptr ) before the call to
work() where the exception gets thrown.

>From the stack trace, that would be at ltask.cc:84


> ** - -it's not null and the debugger traces it into libstd++ where checks
> there
> invalidate it...   But at that point I'm trying to debug an opaque blob that
> is part
> of libstd++ internals.

So stop doing that! Take a step back, the problem is in your code! You
don't need to debug the damn library!
The exception means you have invoked an empty std::function, so stop doing that.

The exception is being thrown here:

  template<typename _Res, typename... _ArgTypes>
    _Res
    function<_Res(_ArgTypes...)>::
    operator()(_ArgTypes... __args) const
    {
      if (_M_empty())
    __throw_bad_function_call();
      return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
    }

The _M_empty() function is returning true, which means the
std::function is empty, it is not valid, you cannot call it, you have
a bug in your code, you need to fix your code.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]