[LLVMbugs] [Bug 23379] New: error code for broken_promise is incorrect & inconsistent with thrown future_error exception

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Apr 30 00:56:10 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23379

            Bug ID: 23379
           Summary: error code for broken_promise is incorrect &
                    inconsistent with thrown future_error exception
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vlovich at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Broken promises on futures have an error code of 0 which results in the weird
result that std::future_errc::broken_promise isn't comparable to any exception
thrown, contrary to the standard specification & all the examples I've found
online.

Steps:
1. 
// test.cpp
#include <future>
#include <iostream>

int main()
{
    std::future<void> f;
    {
        std::promise<void> p;
        f = p.get_future();
    }

    try {
        f.get();
        std::cerr << "Shouldn't get here?\n";
    } catch(const std::future_error& e) {
       bool is_broken_promise = e.code() ==
std::make_error_condition(std::future_errc::broken_promise);
        std::cout << e.code().message() << "\n";
        std::cout << e.code().value() << "\n";
        std::cout << is_broken_promise << "\n";
    }
}

2. clang++ -std=c++11 -stdlib=libc++ test.cpp && ./a.out
3. clang++ -std=c++14 -stdlib=libc++ test.cpp && ./a.out

Actual for both 2 & 3:
The associated promise has been destructed prior to the associated state
becoming ready.
0
0

Expected for #2:
The associated promise has been destructed prior to the associated state
becoming ready.
0
1

or

The associated promise has been destructed prior to the associated state
becoming ready.
0
1

Expected for #3:
The associated promise has been destructed prior to the associated state
becoming ready.
4
1

-- 
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/20150430/a2d6d20a/attachment.html>


More information about the llvm-bugs mailing list