[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 06:50:47 PST 2022


tiagoma created this revision.
tiagoma added a reviewer: ldionne.
tiagoma added a project: libc++.
tiagoma requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

As per [time.duration.cons]/1 the constructor constraint should be on
const Rep2&. As it is now the code will fail to compile in certain
cases, ex:

https://godbolt.org/z/c7fPrcTYM

struct S{
operator int() const&& noexcept = delete;
operator int() const& noexcept;
};

const S &fun();

auto k = std::chrono::microseconds{fun()};


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118902

Files:
  libcxx/include/__chrono/duration.h


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.405624.patch
Type: text/x-patch
Size: 558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220203/ae08a102/attachment-0001.bin>


More information about the libcxx-commits mailing list