]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LWG 3050 Fix cv-qualification of convertibility constraints
authorJonathan Wakely <jwakely@redhat.com>
Wed, 4 Jul 2018 13:59:51 +0000 (14:59 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 4 Jul 2018 13:59:51 +0000 (14:59 +0100)
Backport from mainline
2018-06-18  Jonathan Wakely  <jwakely@redhat.com>

* include/std/chrono (duration, operator*, operator/, operator%): Use
const-qualified type as source type in is_convertible constraints.
* testsuite/20_util/duration/arithmetic/dr3050.cc: New.
* testsuite/20_util/duration/cons/dr3050.cc: New.
* testsuite/20_util/duration/literals/range.cc: Rename to...
* testsuite/20_util/duration/literals/range_neg.cc: Here. Adjust
dg-error lineno.

From-SVN: r262412

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/chrono
libstdc++-v3/testsuite/20_util/duration/cons/dr3050.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/duration/literals/range_neg.cc [moved from libstdc++-v3/testsuite/20_util/duration/literals/range.cc with 94% similarity]

index 772c62fce40605f75b85ee452e535cd10781ccd5..c0b4c5fccbacf40bcfd9e0d52cb207275f670f12 100644 (file)
@@ -1,5 +1,17 @@
 2018-07-04  Jonathan Wakely  <jwakely@redhat.com>
 
+       Backport from mainline
+       2018-06-18  Jonathan Wakely  <jwakely@redhat.com>
+
+       LWG 3050 Fix cv-qualification of convertibility constraints
+       * include/std/chrono (duration, operator*, operator/, operator%): Use
+       const-qualified type as source type in is_convertible constraints.
+       * testsuite/20_util/duration/arithmetic/dr3050.cc: New.
+       * testsuite/20_util/duration/cons/dr3050.cc: New.
+       * testsuite/20_util/duration/literals/range.cc: Rename to...
+       * testsuite/20_util/duration/literals/range_neg.cc: Here. Adjust
+       dg-error lineno.
+
        Backport from mainline
        2018-06-13  Jonathan Wakely  <jwakely@redhat.com>
 
index 5d0151857e70c7f6a31c93b0354ceb5429a6f048..2138ff027e4b2e619ea28b0a4ea01dd08df4e1dc 100644 (file)
@@ -318,8 +318,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
        // constexpr copy constructor will be ill-formed.
        duration(const duration&) = default;
 
+       // _GLIBCXX_RESOLVE_LIB_DEFECTS
+       // 3050. Conversion specification problem in chrono::duration
        template<typename _Rep2, typename = typename
-              enable_if<is_convertible<_Rep2, rep>::value
+              enable_if<is_convertible<const _Rep2&, rep>::value
                         && (treat_as_floating_point<rep>::value
                             || !treat_as_floating_point<_Rep2>::value)>::type>
          constexpr explicit duration(const _Rep2& __rep)
@@ -463,8 +465,12 @@ _GLIBCXX_END_NAMESPACE_VERSION
        return __cd(__cd(__lhs).count() - __cd(__rhs).count());
       }
 
+    // SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2
+    // is implicitly convertible to it.
+    // _GLIBCXX_RESOLVE_LIB_DEFECTS
+    // 3050. Conversion specification problem in chrono::duration constructor
     template<typename _Rep1, typename _Rep2, bool =
-            is_convertible<_Rep2,
+            is_convertible<const _Rep2&,
                            typename common_type<_Rep1, _Rep2>::type>::value>
       struct __common_rep_type { };
 
diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/dr3050.cc b/libstdc++-v3/testsuite/20_util/duration/cons/dr3050.cc
new file mode 100644 (file)
index 0000000..a4f57a3
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) 2018 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <chrono>
+
+struct X { operator int64_t() /* not const */; };
+static_assert(!std::is_constructible<std::chrono::seconds, X>::value,
+             "LWG 3050");
similarity index 94%
rename from libstdc++-v3/testsuite/20_util/duration/literals/range.cc
rename to libstdc++-v3/testsuite/20_util/duration/literals/range_neg.cc
index 531b53c42ec6d2d4364908c747ef96121e018a25..bccff767ef7f1cf11c0f953c8dc6c4a5726c5de4 100644 (file)
@@ -26,6 +26,6 @@ test01()
 
   // std::numeric_limits<int64_t>::max() == 9223372036854775807;
   auto h = 9223372036854775808h;
-  // { dg-error "cannot be represented" "" { target *-*-* } 893 }
+  // { dg-error "cannot be represented" "" { target *-*-* } 899 }
 }
 // { dg-prune-output "in constexpr expansion" } // needed for -O0