LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 23589 - std::function doesn't recognize null pointer to varargs function
Summary: std::function doesn't recognize null pointer to varargs function
Status: RESOLVED FIXED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 3.6
Hardware: PC All
: P normal
Assignee: Eric Fiselier
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-20 01:48 PDT by David Krauss
Modified: 2015-08-19 01:58 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Krauss 2015-05-20 01:48:10 PDT
This crashes:

#include <functional>

void (*p)(...) = nullptr;
std::function< void() > f = p;

int main() {
    try { f(); }
    catch ( std::bad_function_call & ) {}
}


The problem is missing overloads of std::function::__not_null.

On a related note, I'm working on a std::function extension. Is there no facility for function signature decomposition?
Comment 1 Eric Fiselier 2015-05-20 02:37:04 PDT
Looks like __not_null is missing quite a few overloads. Patch up for review as D9873 (http://reviews.llvm.org/D9873).
Comment 2 David Krauss 2015-05-20 03:39:08 PDT
I created an account and left a comment in the review, but it still says "waiting for moderator approval."
--

A lot of work can be saved by ignoring the function signature.

template<class _R2, class _Cp>
static bool not_null(_R2 _Cp::*__p) {return __p;}

--
Actually, you should only need three overloads: one for pointers (including varargs function pointers), one for PTMs (effectively PTMFs but ignoring the function aspects), and the one which is always true.
Comment 3 Eric Fiselier 2015-08-19 01:58:32 PDT
Fixed in r245335.