From 74568c77ef49b2ed2cbb03788aa4511222368db5 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 8 Aug 2018 16:40:57 +0100 Subject: [PATCH] LWG 3050 Fix cv-qualification of convertibility constraints Backport from mainline 2018-06-18 Jonathan Wakely * 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: r263423 --- libstdc++-v3/ChangeLog | 12 ++++++++++ libstdc++-v3/include/std/chrono | 10 ++++++-- .../testsuite/20_util/duration/cons/dr3050.cc | 24 +++++++++++++++++++ .../literals/{range.cc => range_neg.cc} | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/duration/cons/dr3050.cc rename libstdc++-v3/testsuite/20_util/duration/literals/{range.cc => range_neg.cc} (94%) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 160ed577a322..4db1d7afa197 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,17 @@ 2018-08-08 Jonathan Wakely + Backport from mainline + 2018-06-18 Jonathan Wakely + + 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 2017-11-16 Jonathan Wakely diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index b4f5f10a1649..76f5d0873636 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -256,8 +256,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::value + enable_if::value && (treat_as_floating_point::value || !treat_as_floating_point<_Rep2>::value)>::type> constexpr explicit duration(const _Rep2& __rep) @@ -399,8 +401,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::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 index 000000000000..a4f57a38c302 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/dr3050.cc @@ -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 +// . + +// { dg-do compile { target c++11 } } + +#include + +struct X { operator int64_t() /* not const */; }; +static_assert(!std::is_constructible::value, + "LWG 3050"); diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc b/libstdc++-v3/testsuite/20_util/duration/literals/range_neg.cc 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 acbfab009921..cb83186c9e6d 100644 --- a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc +++ b/libstdc++-v3/testsuite/20_util/duration/literals/range_neg.cc @@ -27,5 +27,5 @@ test01() // std::numeric_limits::max() == 9223372036854775807; auto h = 9223372036854775808h; - // { dg-error "cannot be represented" "" { target *-*-* } 798 } + // { dg-error "cannot be represented" "" { target *-*-* } 804 } } -- 2.47.2