From e4f32cb0a55eefcd56b1c42bcaf5c8aadc692ba6 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 10 Jun 2010 00:43:50 +0000 Subject: [PATCH] type_traits (is_nothrow_constructible): Add. 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. From-SVN: r160523 --- libstdc++-v3/ChangeLog | 18 +++++ libstdc++-v3/include/std/type_traits | 26 ++++++- .../20_util/declval/requirements/1_neg.cc | 2 +- .../requirements/explicit_instantiation.cc | 31 ++++++++ .../requirements/typedefs.cc | 36 +++++++++ .../20_util/is_nothrow_constructible/value.cc | 78 +++++++++++++++++++ .../make_signed/requirements/typedefs_neg.cc | 4 +- .../requirements/typedefs_neg.cc | 4 +- libstdc++-v3/testsuite/util/testsuite_tr1.h | 34 +++++++- 9 files changed, 225 insertions(+), 8 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_nothrow_constructible/value.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2ea2b298fe1..82fc51d3ace 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +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. + 2010-06-09 Khem Raj PR libstdc++/44461 diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index ba9d62c24cd..42a462e53a5 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -193,7 +193,7 @@ namespace std { }; 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 @@ namespace std _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 @@ namespace std template inline typename add_rvalue_reference<_Tp>::type - declval() + declval() noexcept { static_assert(__declval_protector<_Tp>::__stop, "declval() must not be used!"); diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc index c3b5022f77a..727f1c47ac9 100644 --- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -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" } diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..37ba9eb8bc1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc @@ -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; +} diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc new file mode 100644 index 00000000000..53a64a78f3f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc @@ -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; +} diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/value.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/value.cc new file mode 100644 index 00000000000..b3246fad119 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/value.cc @@ -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; +} diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc index 7a8ad661d85..8f626628ef7 100644 --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -48,8 +48,8 @@ void test01() // { 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" } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc index 23bca2bffa2..3648236db64 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -48,8 +48,8 @@ void test01() // { 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" } diff --git a/libstdc++-v3/testsuite/util/testsuite_tr1.h b/libstdc++-v3/testsuite/util/testsuite_tr1.h index 4f3e574ccc2..5aac18292bb 100644 --- a/libstdc++-v3/testsuite/util/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/util/testsuite_tr1.h @@ -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 @@ namespace __gnu_test { 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;