[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


http://llvm.org/bugs/show_bug.cgi?id=16633

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.

But:

    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:

http://stackoverflow.com/questions/5931214/isnt-the-template-argument-the-signature-of-stdfunction-part-of-its-type

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:

http://cplusplus.github.io/LWG/lwg-closed.html#1024

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