+2008-07-31 Chris Fairles <chris.fairles@gmail.com>
+
+ * 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 <paolo.carlini@oracle.com>
* testsuite/lib/libstdc++.exp (libstdc++_init): Set v3-libgomp.
{ return numeric_limits<_Rep>::min(); }
};
+ template<typename _Tp>
+ struct __is_duration
+ : std::false_type
+ { };
+
+ template<typename _Rep, typename _Period>
+ struct __is_duration<duration<_Rep, _Period>>
+ : std::true_type
+ { };
+
+ template<typename T>
+ struct __is_ratio
+ : std::false_type
+ { };
+
+ template<intmax_t _Num, intmax_t _Den>
+ struct __is_ratio<ratio<_Num, _Den>>
+ : std::true_type
+ { };
+
/// duration
template<typename _Rep, typename _Period>
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<typename _Rep2>
explicit duration(_Rep2 const& __rep)
: __r(static_cast<rep>(__rep))
{
- static_assert(is_convertible<_Rep2,rep>::value == true
- && (treat_as_floating_point<rep>::value == true
- || (!treat_as_floating_point<rep>::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<rep>::value
+ || !treat_as_floating_point<_Rep2>::value),
+ "cannot construct integral duration with floating point type");
}
- duration(const duration& __d)
- : __r(__d.count())
- { }
-
- // conversions
template<typename _Rep2, typename _Period2>
duration(const duration<_Rep2, _Period2>& __d)
: __r(duration_cast<duration>(__d).count())
"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; }
return *this;
}
- // special values
+ // 20.8.3.4 special values
// TODO: These should be constexprs.
static const duration
zero()
operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d)
{ return __d * __s; }
- template<typename _Tp>
- struct __is_not_duration
- : std::true_type
- { };
-
- template<typename _Rep, typename _Period>
- struct __is_not_duration<duration<_Rep, _Period>>
- : std::false_type
- { };
-
template<typename _Tp, typename _Up, typename _Ep = void>
struct __division_impl;
template<typename _Rep1, typename _Period, typename _Rep2>
struct __division_impl<duration<_Rep1, _Period>, _Rep2,
- typename enable_if<__is_not_duration<_Rep2>::value>::type>
+ typename enable_if<!__is_duration<_Rep2>::value>::type>
{
typedef typename common_type<_Rep1, _Rep2>::type __cr;
typedef
// { 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" }
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// 2008-07-31 Chris Fairles <chris.fairles@gmail.com>
+
+// 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 <chrono>
+
+void test01()
+{
+ // Check if rep is a duration type
+ typedef std::chrono::duration<int> rep_type;
+ typedef std::chrono::duration<rep_type> 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" }
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// 2008-07-31 Chris Fairles <chris.fairles@gmail.com>
+
+// 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 <chrono>
+
+void test01()
+{
+ // Check if period is a ratio
+ typedef int rep_type;
+ typedef int period_type;
+ typedef std::chrono::duration<rep_type, period_type> 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" }
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// 2008-07-31 Chris Fairles <chris.fairles@gmail.com>
+
+// 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 <ratio>
+#include <chrono>
+
+void test01()
+{
+ // Check if period is positive
+ typedef int rep_type;
+ typedef std::ratio<-1> period_type;
+ typedef std::chrono::duration<rep_type, period_type> 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" }