From 9d4e8554deb0b157ff12caabc894f77c6d44f6c0 Mon Sep 17 00:00:00 2001 From: Chris Fairles Date: Thu, 31 Jul 2008 19:37:21 +0000 Subject: [PATCH] chrono (duration): Use explicitly defaulted ctor, cctor, dtor and assignment. 2008-07-31 Chris Fairles * include/std/chrono (duration): Use explicitly defaulted ctor, cctor, dtor and assignment. Add diagnostics as per 20.8.3 paragraphs 2, 3 and 4 in WD. Other minor tweaks. * testsuite/20_util/duration/cons/1_neg.cc: Adjust line numbers. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: New. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Likewise. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise. From-SVN: r138434 --- libstdc++-v3/ChangeLog | 10 +++ libstdc++-v3/include/std/chrono | 65 +++++++++++-------- .../testsuite/20_util/duration/cons/1_neg.cc | 4 +- .../duration/requirements/typedefs_neg1.cc | 45 +++++++++++++ .../duration/requirements/typedefs_neg2.cc | 46 +++++++++++++ .../duration/requirements/typedefs_neg3.cc | 47 ++++++++++++++ 6 files changed, 187 insertions(+), 30 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 93892d125fe..3cc11cf302c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2008-07-31 Chris Fairles + + * include/std/chrono (duration): Use explicitly defaulted ctor, cctor, + dtor and assignment. Add diagnostics as per 20.8.3 paragraphs 2, 3 + and 4 in WD. Other minor tweaks. + * testsuite/20_util/duration/cons/1_neg.cc: Adjust line numbers. + * testsuite/20_util/duration/requirements/typedefs_neg1.cc: New. + * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Likewise. + * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise. + 2008-07-31 Paolo Carlini * testsuite/lib/libstdc++.exp (libstdc++_init): Set v3-libgomp. diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index b5fd1fd209e..d20c7f45cd9 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -166,36 +166,51 @@ namespace std { return numeric_limits<_Rep>::min(); } }; + template + struct __is_duration + : std::false_type + { }; + + template + struct __is_duration> + : std::true_type + { }; + + template + struct __is_ratio + : std::false_type + { }; + + template + struct __is_ratio> + : std::true_type + { }; + /// duration template struct duration { + static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); + static_assert(__is_ratio<_Period>::value, + "period must be a specialization of ratio"); static_assert(_Period::num > 0, "period must be positive"); typedef _Rep rep; typedef _Period period; - // construction / destruction - duration () - : __r(rep(0)) - { } + // 20.8.3.1 construction / copy / destroy + duration() = default; template explicit duration(_Rep2 const& __rep) : __r(static_cast(__rep)) { - static_assert(is_convertible<_Rep2,rep>::value == true - && (treat_as_floating_point::value == true - || (!treat_as_floating_point::value - && !treat_as_floating_point<_Rep2>::value)), - "cannot construct integral duration with floating point type"); + static_assert(is_convertible<_Rep2,rep>::value + && (treat_as_floating_point::value + || !treat_as_floating_point<_Rep2>::value), + "cannot construct integral duration with floating point type"); } - duration(const duration& __d) - : __r(__d.count()) - { } - - // conversions template duration(const duration<_Rep2, _Period2>& __d) : __r(duration_cast(__d).count()) @@ -205,12 +220,16 @@ namespace std "the resulting duration is not exactly representable"); } - // observer + ~duration() = default; + duration(const duration&) = default; + duration& operator=(const duration&) = default; + + // 20.8.3.2 observer rep count() const { return __r; } - // arithmetic + // 20.8.3.3 arithmetic duration operator+() const { return *this; } @@ -269,7 +288,7 @@ namespace std return *this; } - // special values + // 20.8.3.4 special values // TODO: These should be constexprs. static const duration zero() @@ -324,22 +343,12 @@ namespace std operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d) { return __d * __s; } - template - struct __is_not_duration - : std::true_type - { }; - - template - struct __is_not_duration> - : std::false_type - { }; - template struct __division_impl; template struct __division_impl, _Rep2, - typename enable_if<__is_not_duration<_Rep2>::value>::type> + typename enable_if::value>::type> { typedef typename common_type<_Rep1, _Rep2>::type __cr; typedef diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc b/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc index fa63dab22b5..d8b08dbd4f8 100644 --- a/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc @@ -41,6 +41,6 @@ test02() // { dg-error "instantiated from here" "" { target *-*-* } 30 } // { dg-error "instantiated from here" "" { target *-*-* } 39 } -// { dg-error "not exactly representable" "" { target *-*-* } 203 } -// { dg-error "integral duration with floating point" "" { target *-*-* } 187 } +// { dg-error "not exactly representable" "" { target *-*-* } 218 } +// { dg-error "integral duration with floating point" "" { target *-*-* } 208 } // { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc new file mode 100644 index 00000000000..188950d6347 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// 2008-07-31 Chris Fairles + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include + +void test01() +{ + // Check if rep is a duration type + typedef std::chrono::duration rep_type; + typedef std::chrono::duration test_type; + test_type d; +} + +// { dg-error "rep cannot be a duration" "" { target *-*-* } 193 } +// { dg-error "instantiated from here" "" { target *-*-* } 40 } +// { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc new file mode 100644 index 00000000000..783044fada6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// 2008-07-31 Chris Fairles + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include + +void test01() +{ + // Check if period is a ratio + typedef int rep_type; + typedef int period_type; + typedef std::chrono::duration test_type; + test_type d; +} + +// { dg-error "must be a specialization of ratio" "" { target *-*-* } 194 } +// { dg-error "instantiated from here" "" { target *-*-* } 41 } +// { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc new file mode 100644 index 00000000000..2896845d7d2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc @@ -0,0 +1,47 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// 2008-07-31 Chris Fairles + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include + +void test01() +{ + // Check if period is positive + typedef int rep_type; + typedef std::ratio<-1> period_type; + typedef std::chrono::duration test_type; + test_type d; +} + +// { dg-error "period must be positive" "" { target *-*-* } 196 } +// { dg-error "instantiated from here" "" { target *-*-* } 42 } +// { dg-excess-errors "In instantiation of" }