This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Implement DR 974
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 27 Oct 2009 02:19:20 +0100
- Subject: [v3] Implement DR 974
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
//////////////////////
2009-10-26 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/chrono (duration<>::duration(const duration<>&)): Fix
per the straightforward resolution of DR 974.
* testsuite/20_util/duration/cons/dr974.cc: Add.
Index: include/std/chrono
===================================================================
--- include/std/chrono (revision 153577)
+++ include/std/chrono (working copy)
@@ -225,7 +225,8 @@
: __r(duration_cast<duration>(__d).count())
{
static_assert(treat_as_floating_point<rep>::value == true
- || ratio_divide<_Period2, period>::type::den == 1,
+ || (ratio_divide<_Period2, period>::type::den == 1
+ && !treat_as_floating_point<_Rep2>::value),
"the resulting duration is not exactly representable");
}
Index: testsuite/20_util/duration/cons/dr974.cc
===================================================================
--- testsuite/20_util/duration/cons/dr974.cc (revision 0)
+++ testsuite/20_util/duration/cons/dr974.cc (revision 0)
@@ -0,0 +1,37 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+
+// Copyright (C) 2009 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
+// <http://www.gnu.org/licenses/>.
+
+// 20.8.3.1 duration constructors [time.duration.cons]
+
+#include <chrono>
+
+// DR 974.
+void test01()
+{
+ using namespace std::chrono;
+
+ duration<double> d(3.5);
+ duration<int> i = d; // implicit truncation, should not compile
+}
+
+// { dg-error "instantiated from here" "" { target *-*-* } 32 }
+// { dg-error "not exactly representable" "" { target *-*-* } 227 }
+// { dg-excess-errors "In instantiation of" }