[LLVMbugs] [Bug 16633] std::function return type cannot automatically cast to void

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 16 08:03:16 PDT 2013


Howard Hinnant <hhinnant at apple.com> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Howard Hinnant <hhinnant at apple.com> ---
This is a feature, not a bug.  The example violates [func.wrap.func]/p2 and p7
which require the functor to be Callable for argument types ArgTyeps and return
type R.  The definition of Callable requires the result of the functor to be
implicitly convertible to R.


    static_assert(!std::is_convertible<bool, void>::value, "");

which is specified in [meta.rel]/p4.

The violation of this requirement results in undefined behavior, meaning
anything can happen.  It is legal for the implementation to compile and execute
the code.  It is legal for the implementation to refuse to compile it.

libc++ used to compile and execute this code.  However that was causing
problems too.  For example this SO question:


complains of an ambiguity.  The ambiguity can be resolved by eliminating the
function(F) constructor when F is not Callable.

It is possible that a future standard may require this behavior:


Here is one way to work around this requirement:

    std::function<void ()> fns = [](){std::bind(fn, true)();};

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130716/01c20784/attachment.html>

More information about the llvm-bugs mailing list