Commit 8499a82c by Jonathan Wakely Committed by Jonathan Wakely

LWG 3050 Fix cv-qualification of convertibility constraints

	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.

From-SVN: r261708
parent 4f9eae9f
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.
2018-06-18 Maya Rashish <coypu@sdf.org> 2018-06-18 Maya Rashish <coypu@sdf.org>
* crossconfig.m4: Handle OpenBSD just like NetBSD. * crossconfig.m4: Handle OpenBSD just like NetBSD.
......
...@@ -325,8 +325,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -325,8 +325,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
duration(const duration&) = default; duration(const duration&) = default;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 3050. Conversion specification problem in chrono::duration
template<typename _Rep2, typename = _Require< template<typename _Rep2, typename = _Require<
is_convertible<_Rep2, rep>, is_convertible<const _Rep2&, rep>,
__or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>> __or_<__is_float<rep>, __not_<__is_float<_Rep2>>>>>
constexpr explicit duration(const _Rep2& __rep) constexpr explicit duration(const _Rep2& __rep)
: __r(static_cast<rep>(__rep)) { } : __r(static_cast<rep>(__rep)) { }
...@@ -471,10 +473,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -471,10 +473,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2 // SFINAE helper to obtain common_type<_Rep1, _Rep2> only if _Rep2
// is implicitly convertible to it. // is implicitly convertible to it.
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 3050. Conversion specification problem in chrono::duration constructor
template<typename _Rep1, typename _Rep2, template<typename _Rep1, typename _Rep2,
typename _CRep = typename common_type<_Rep1, _Rep2>::type> typename _CRep = typename common_type<_Rep1, _Rep2>::type>
using __common_rep_t using __common_rep_t = typename
= typename enable_if<is_convertible<_Rep2, _CRep>::value, _CRep>::type; enable_if<is_convertible<const _Rep2&, _CRep>::value, _CRep>::type;
template<typename _Rep1, typename _Period, typename _Rep2> template<typename _Rep1, typename _Period, typename _Rep2>
constexpr duration<__common_rep_t<_Rep1, _Rep2>, _Period> constexpr duration<__common_rep_t<_Rep1, _Rep2>, _Period>
......
// 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");
...@@ -26,6 +26,6 @@ test01() ...@@ -26,6 +26,6 @@ test01()
// std::numeric_limits<int64_t>::max() == 9223372036854775807; // std::numeric_limits<int64_t>::max() == 9223372036854775807;
auto h = 9223372036854775808h; auto h = 9223372036854775808h;
// { dg-error "cannot be represented" "" { target *-*-* } 894 } // { dg-error "cannot be represented" "" { target *-*-* } 898 }
} }
// { dg-prune-output "in constexpr expansion" } // needed for -O0 // { dg-prune-output "in constexpr expansion" } // needed for -O0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment