This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: How to get more info about 'bad_function_call' ?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "Linda A. Walsh" <gcc at tlinx dot org>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 27 Jan 2015 17:15:33 +0000
- Subject: Re: How to get more info about 'bad_function_call' ?
- Authentication-results: sourceware.org; auth=none
- References: <54C7A9F8 dot 70504 at tlinx dot org> <CAH6eHdQemyPo80Kq4g-tGvyqqvFrUP4jtPOLr8wyz_rAwfk__A at mail dot gmail dot com> <54C7C339 dot 5020401 at tlinx dot org>
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.