From patchwork Thu Jun 10 00:42:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 55135 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 A4F611007D2 for ; Thu, 10 Jun 2010 10:42:55 +1000 (EST) Received: (qmail 20077 invoked by alias); 10 Jun 2010 00:42:53 -0000 Received: (qmail 20057 invoked by uid 22791); 10 Jun 2010 00:42:50 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp4.tin.it (HELO vsmtp4.tin.it) (212.216.176.224) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Jun 2010 00:42:42 +0000 Received: from [192.168.0.4] (79.53.235.62) by vsmtp4.tin.it (8.5.113) id 4BCE3CBE04D92129; Thu, 10 Jun 2010 02:42:39 +0200 Message-ID: <4C1034FF.3050806@oracle.com> Date: Thu, 10 Jun 2010 02:42:39 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100317 SUSE/3.0.4-1.1.1 Thunderbird/3.0.4 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Add is_nothrow_constructible X-IsSubscribed: yes 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 Hi, tested x86_64-linux, committed to mainline. Paolo. ////////////////// 2010-06-09 Paolo Carlini * include/std/type_traits (is_nothrow_constructible): Add. (declval): Add noexcept specification. * testsuite/util/testsuite_tr1.h (struct NothrowExplicitClass, ThrowExplicitClass, NoexceptExplicitClass, ExceptExplicitClass): Add. * testsuite/20_util/is_nothrow_constructible/value.cc: New. * testsuite/20_util/is_nothrow_constructible/requirements/ typedefs.cc: Likewise. * testsuite/20_util/is_nothrow_constructible/requirements/ explicit_instantiation.cc: Likewise. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust dg-error line numbers. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/declval/requirements/1_neg.cc: Likewise. Index: include/std/type_traits =================================================================== --- include/std/type_traits (revision 160490) +++ include/std/type_traits (working copy) @@ -193,7 +193,7 @@ { }; template - typename add_rvalue_reference<_Tp>::type declval(); + typename add_rvalue_reference<_Tp>::type declval() noexcept; template class __is_constructible_helper @@ -234,6 +234,28 @@ _Args...>::__value> { }; + template + struct __is_nt_constructible_helper + { static const bool __value = false; }; + + template + struct __is_nt_constructible_helper + { static const bool __value = noexcept(_Tp(declval<_Args>()...)); }; + + template + struct __is_nt_constructible_helper + { + static const bool __value = noexcept(static_cast<_Tp>(declval<_Arg>())); + }; + + /// is_nothrow_constructible + template + struct is_nothrow_constructible + : public integral_constant::value, + _Tp, _Args...>::__value> + { }; + /// has_trivial_default_constructor template struct has_trivial_default_constructor @@ -649,7 +671,7 @@ template inline typename add_rvalue_reference<_Tp>::type - declval() + declval() noexcept { static_assert(__declval_protector<_Tp>::__stop, "declval() must not be used!"); Index: testsuite/util/testsuite_tr1.h =================================================================== --- testsuite/util/testsuite_tr1.h (revision 160490) +++ testsuite/util/testsuite_tr1.h (working copy) @@ -1,7 +1,8 @@ // -*- C++ -*- // Testing utilities for the tr1 testsuite. // -// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 +// Free Software Foundation, Inc. // // 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 @@ -127,8 +128,39 @@ { ExplicitClass(double&); explicit ExplicitClass(int&); + ExplicitClass(double&, int&, double&); }; + struct NothrowExplicitClass + { + NothrowExplicitClass(double&) throw(); + explicit NothrowExplicitClass(int&) throw(); + NothrowExplicitClass(double&, int&, double&) throw(); + }; + + struct ThrowExplicitClass + { + ThrowExplicitClass(double&) throw(int); + explicit ThrowExplicitClass(int&) throw(int); + ThrowExplicitClass(double&, int&, double&) throw(int); + }; + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + struct NoexceptExplicitClass + { + NoexceptExplicitClass(double&) noexcept(true); + explicit NoexceptExplicitClass(int&) noexcept(true); + NoexceptExplicitClass(double&, int&, double&) noexcept(true); + }; + + struct ExceptExplicitClass + { + ExceptExplicitClass(double&) noexcept(false); + explicit ExceptExplicitClass(int&) noexcept(false); + ExceptExplicitClass(double&, int&, double&) noexcept(false); + }; +#endif + struct NType // neither trivial nor standard-layout { int i; Index: testsuite/20_util/is_nothrow_constructible/value.cc =================================================================== --- testsuite/20_util/is_nothrow_constructible/value.cc (revision 0) +++ testsuite/20_util/is_nothrow_constructible/value.cc (revision 0) @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-09 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// 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 +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_nothrow_constructible; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_property(true)) ); + VERIFY( (test_property(true)) ); + VERIFY( (test_property(true)) ); + VERIFY( (test_property(true)) ); + VERIFY( (test_property(true)) ); + VERIFY( (test_property(true)) ); + + // Negative tests. + VERIFY( (test_property(false)) ); + VERIFY( (test_property + (false)) ); + VERIFY( (test_property(false)) ); + VERIFY( (test_property(false)) ); + VERIFY( (test_property + (false)) ); + VERIFY( (test_property(false)) ); + + VERIFY( (test_property(false)) ); + VERIFY( (test_property(false)) ); + VERIFY( (test_property(false)) ); + VERIFY( (test_property(false)) ); + VERIFY( (test_property(false)) ); + VERIFY( (test_property(false)) ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc =================================================================== --- testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc (revision 0) +++ testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc (revision 0) @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-06-09 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// 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 +// . + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +void test01() +{ + // Check for required typedefs + typedef std::is_nothrow_constructible test_type; + typedef test_type::value_type value_type; + typedef test_type::type type; + typedef test_type::type::value_type type_value_type; + typedef test_type::type::type type_type; +} Index: testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc =================================================================== --- testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc (revision 0) +++ testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc (revision 0) @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-06-09 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// 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 +// . + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + typedef short test_type; + template struct is_nothrow_constructible; +} Index: testsuite/20_util/make_signed/requirements/typedefs_neg.cc =================================================================== --- testsuite/20_util/make_signed/requirements/typedefs_neg.cc (revision 160490) +++ testsuite/20_util/make_signed/requirements/typedefs_neg.cc (working copy) @@ -48,8 +48,8 @@ // { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 617 } -// { dg-error "declaration of" "" { target *-*-* } 581 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 639 } +// { dg-error "declaration of" "" { target *-*-* } 603 } // { dg-excess-errors "At global scope" } // { dg-excess-errors "In instantiation of" } Index: testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc =================================================================== --- testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc (revision 160490) +++ testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc (working copy) @@ -48,8 +48,8 @@ // { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 540 } -// { dg-error "declaration of" "" { target *-*-* } 504 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 562 } +// { dg-error "declaration of" "" { target *-*-* } 526 } // { dg-excess-errors "At global scope" } // { dg-excess-errors "In instantiation of" } Index: testsuite/20_util/declval/requirements/1_neg.cc =================================================================== --- testsuite/20_util/declval/requirements/1_neg.cc (revision 160490) +++ testsuite/20_util/declval/requirements/1_neg.cc (working copy) @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 654 } +// { dg-error "static assertion failed" "" { target *-*-* } 676 } // { dg-error "instantiated from here" "" { target *-*-* } 30 } // { dg-excess-errors "In function" }