[libcxx-commits] [PATCH] D118902: [libc++] Fix chrono::duration constructor constraint

Tiago Macarios via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 3 07:17:32 PST 2022


tiagoma updated this revision to Diff 405633.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118902/new/

https://reviews.llvm.org/D118902

Files:
  libcxx/include/__chrono/duration.h
  libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp


Index: libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp
===================================================================
--- libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp
+++ libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp
@@ -39,5 +39,14 @@
     test<std::chrono::duration<Rep, std::ratio<3, 2> > >(Rep(3));
     test<std::chrono::duration<double, std::ratio<2, 3> > >(5.5);
 
-  return 0;
+    // test for [time.duration.cons]/1
+    struct NotValueConvertible {
+      operator int() const&& noexcept = delete;
+      operator int() const& noexcept { return 1; }
+    };
+    const NotValueConvertible& NVC = {};
+
+    test<std::chrono::duration<int> >(NVC);
+
+    return 0;
 }
Index: libcxx/include/__chrono/duration.h
===================================================================
--- libcxx/include/__chrono/duration.h
+++ libcxx/include/__chrono/duration.h
@@ -251,7 +251,7 @@
         explicit duration(const _Rep2& __r,
             typename enable_if
             <
-               is_convertible<_Rep2, rep>::value &&
+               is_convertible<const _Rep2&, rep>::value &&
                (treat_as_floating_point<rep>::value ||
                !treat_as_floating_point<_Rep2>::value)
             >::type* = nullptr)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118902.405633.patch
Type: text/x-patch
Size: 1332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220203/2f8a6f18/attachment.bin>


More information about the libcxx-commits mailing list