diff --git a/libcxx/include/__chrono/duration.h b/libcxx/include/__chrono/duration.h index 24801772ec5d8..b7d88cb52ea83 100644 --- a/libcxx/include/__chrono/duration.h +++ b/libcxx/include/__chrono/duration.h @@ -251,7 +251,7 @@ class _LIBCPP_TEMPLATE_VIS duration explicit duration(const _Rep2& __r, typename enable_if < - is_convertible<_Rep2, rep>::value && + is_convertible::value && (treat_as_floating_point::value || !treat_as_floating_point<_Rep2>::value) >::type* = nullptr) diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp index 92dbc5e9b62ad..252f5032966a5 100644 --- a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp @@ -20,24 +20,45 @@ #include "test_macros.h" #include "../../rep.h" +#if TEST_STD_VER >= 11 +struct NotValueConvertible { + operator int() const&& = delete; + constexpr operator int() const& { return 1; } +}; +#endif + template -void -test(R r) -{ +TEST_CONSTEXPR_CXX14 void check(R r) { D d(r); assert(d.count() == r); +} + +TEST_CONSTEXPR_CXX14 bool test() { + check >(5); + check > >(5); + check > >(Rep(3)); + check > >(5.5); + + // test for [time.duration.cons]/1 #if TEST_STD_VER >= 11 - constexpr D d2(R(2)); - static_assert(d2.count() == 2, ""); + check >(NotValueConvertible()); #endif + + return true; } -int main(int, char**) -{ - test >(5); - test > >(5); - test > >(Rep(3)); - test > >(5.5); +int main(int, char**) { + test(); +#if TEST_STD_VER > 11 + static_assert(test(), ""); +#endif - return 0; + // Basic test for constexpr-friendliness in C++11 +#if TEST_STD_VER >= 11 + { + constexpr std::chrono::duration d(5); + static_assert(d.count() == 5, ""); + } +#endif + return 0; }