Commit 5f031f97 by Jonathan Wakely

libstdc++: midpoint should not constrain T is complete (LWG 3200)

	* include/std/numeric (midpoint(T8, T*)): Do not check for complete
	type during overload resolution, use static assert instead (LWG 3200).
	* testsuite/26_numerics/midpoint/pointer.cc: Do not test with
	incomplete type.
	* testsuite/26_numerics/midpoint/pointer_neg.cc: New test.
parent 66ae31eb
2020-02-19 Jonathan Wakely <jwakely@redhat.com> 2020-02-19 Jonathan Wakely <jwakely@redhat.com>
* include/std/numeric (midpoint(T8, T*)): Do not check for complete
type during overload resolution, use static assert instead (LWG 3200).
* testsuite/26_numerics/midpoint/pointer.cc: Do not test with
incomplete type.
* testsuite/26_numerics/midpoint/pointer_neg.cc: New test.
* include/std/span (span(T (&)[N])): Use non-deduced context to * include/std/span (span(T (&)[N])): Use non-deduced context to
prevent first parameter from interfering with class template argument prevent first parameter from interfering with class template argument
deduction (LWG 3369). deduction (LWG 3369).
......
...@@ -208,10 +208,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -208,10 +208,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
template<typename _Tp> template<typename _Tp>
constexpr constexpr enable_if_t<is_object_v<_Tp>, _Tp*>
enable_if_t<__and_v<is_object<_Tp>, bool_constant<sizeof(_Tp) != 0>>, _Tp*>
midpoint(_Tp* __a, _Tp* __b) noexcept midpoint(_Tp* __a, _Tp* __b) noexcept
{ {
static_assert( sizeof(_Tp) != 0, "type must be complete" );
return __a + (__b - __a) / 2; return __a + (__b - __a) / 2;
} }
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
// { dg-do run { target c++2a } } // { dg-do run { target c++2a } }
#include <numeric> #include <numeric>
#include <climits>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
const int* p = nullptr; const int* p = nullptr;
...@@ -36,7 +35,6 @@ template<typename T> constexpr bool no_midpoint() ...@@ -36,7 +35,6 @@ template<typename T> constexpr bool no_midpoint()
static_assert(no_midpoint<void>()); static_assert(no_midpoint<void>());
static_assert(no_midpoint<int()>()); static_assert(no_midpoint<int()>());
static_assert(no_midpoint<int&>()); static_assert(no_midpoint<int&>());
static_assert(no_midpoint<struct Incomplete>());
constexpr int ca[3] = {}; constexpr int ca[3] = {};
static_assert( std::midpoint(ca, ca+3) == ca+1 ); static_assert( std::midpoint(ca, ca+3) == ca+1 );
......
// Copyright (C) 2020 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-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <numeric>
// LWG 3200. midpoint should not constrain T is complete
struct Incomplete* pinc = 0;
auto p1 = std::midpoint(pinc, pinc); // { dg-error "here" }
// { dg-error "incomplete type" "" { target *-*-* } 0 }
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