From patchwork Tue Dec 14 23:31:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 75584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id DBA66B6F14 for ; Wed, 15 Dec 2010 10:32:14 +1100 (EST) Received: (qmail 19548 invoked by alias); 14 Dec 2010 23:32:09 -0000 Received: (qmail 19283 invoked by uid 22791); 14 Dec 2010 23:32:06 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Dec 2010 23:32:01 +0000 Received: by wwe15 with SMTP id 15so976664wwe.8 for ; Tue, 14 Dec 2010 15:31:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.170.213 with SMTP id p63mr5585053wel.6.1292369516721; Tue, 14 Dec 2010 15:31:56 -0800 (PST) Received: by 10.216.160.131 with HTTP; Tue, 14 Dec 2010 15:31:56 -0800 (PST) Date: Tue, 14 Dec 2010 23:31:56 +0000 Message-ID: Subject: [v3] fix libstdc++/45133 From: Jonathan Wakely To: "libstdc++" , gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This implements the behaviour encouraged by the new note on 30.6.6p3 and 30.6.7p3 in the latest C++0x draft. 2010-12-14 Jonathan Wakely PR libstdc++/45133 * include/std/future (__basic_future::wait): Throw if not valid. (__basic_future::wait_for): Likewise. (__basic_future::wait_until): Likewise. (__basic_future::_M_get_result): Likewise. * testsuite/30_threads/future/members/45133.cc: New. * testsuite/30_threads/shared_future/members/45133.cc: New. tested x86_64-linux, checked in to trunk Index: include/std/future =================================================================== --- include/std/future (revision 167789) +++ include/std/future (working copy) @@ -508,23 +508,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std) valid() const { return static_cast(_M_state); } void - wait() const { _M_state->wait(); } + wait() const + { + _State::_S_check(_M_state); + _M_state->wait(); + } template bool wait_for(const chrono::duration<_Rep, _Period>& __rel) const - { return _M_state->wait_for(__rel); } + { + _State::_S_check(_M_state); + return _M_state->wait_for(__rel); + } template bool wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const - { return _M_state->wait_until(__abs); } + { + _State::_S_check(_M_state); + return _M_state->wait_until(__abs); + } protected: /// Wait for the state to be ready and rethrow any stored exception __result_type _M_get_result() { + _State::_S_check(_M_state); _Result_base& __res = _M_state->wait(); if (!(__res._M_error == 0)) rethrow_exception(__res._M_error); Index: testsuite/30_threads/shared_future/members/45133.cc =================================================================== --- testsuite/30_threads/shared_future/members/45133.cc (revision 0) +++ testsuite/30_threads/shared_future/members/45133.cc (revision 0) @@ -0,0 +1,90 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 30.6.7 Class template shared_future [futures.shared_future] + +#include +#include + +// This test verifies behaviour which is encouraged by a non-normative note, +// but not required. + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_future f; + try + { + f.get(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY( e.code() == std::future_errc::no_state ); + } +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_future f; + try + { + f.get(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY( e.code() == std::future_errc::no_state ); + } +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::shared_future f; + try + { + f.get(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY( e.code() == std::future_errc::no_state ); + } +} + +int main() +{ + test01(); + test02(); + test03(); + + return 0; +} + Index: testsuite/30_threads/future/members/45133.cc =================================================================== --- testsuite/30_threads/future/members/45133.cc (revision 0) +++ testsuite/30_threads/future/members/45133.cc (revision 0) @@ -0,0 +1,100 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 30.6.6 Class template future [futures.unique_future] + +#include +#include + +// This test verifies behaviour which is encouraged by a non-normative note, +// but not required. + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::promise p; + std::future f = p.get_future(); + p.set_value(0); + f.get(); + try + { + f.get(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY( e.code() == std::future_errc::no_state ); + } +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::promise p; + std::future f = p.get_future(); + int i = 0; + p.set_value(i); + f.get(); + try + { + f.get(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY( e.code() == std::future_errc::no_state ); + } +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::promise p; + std::future f = p.get_future(); + p.set_value(); + f.get(); + try + { + f.get(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY( e.code() == std::future_errc::no_state ); + } +} + +int main() +{ + test01(); + test02(); + test03(); + + return 0; +} +