Skip to content
Snippets Groups Projects
Unverified Commit 3aeb2ede authored by Jonathan Wakely's avatar Jonathan Wakely Committed by Jonathan Wakely
Browse files

libstdc++: Skip redundant assertions in std::array equality [PR106212]

As PR c++/106212 shows, the Debug Mode checks cause a compilation error
for equality comparisons involving std::array prvalues in constant
expressions. Those Debug Mode checks are redundant when
comparing two std::array objects, because we already know we have a
valid range. We can also avoid the unnecessary step of using
std::__niter_base to do __normal_iterator unwrapping, which isn't needed
because our std::array iterators are just pointers. Using
std::__equal_aux1 instead of std::equal avoids the redundant checks in
std::equal and std::__equal_aux.

libstdc++-v3/ChangeLog:

	PR libstdc++/106212
	* include/std/array (operator==): Use std::__equal_aux1 instead
	of std::equal.
	* testsuite/23_containers/array/comparison_operators/106212.cc:
	New test.
parent e95bda02
No related branches found
No related tags found
No related merge requests found
...@@ -303,7 +303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -303,7 +303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX20_CONSTEXPR _GLIBCXX20_CONSTEXPR
inline bool inline bool
operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return std::equal(__one.begin(), __one.end(), __two.begin()); } { return std::__equal_aux1(__one.begin(), __one.end(), __two.begin()); }
#if __cpp_lib_three_way_comparison // C++ >= 20 && lib_concepts #if __cpp_lib_three_way_comparison // C++ >= 20 && lib_concepts
template<typename _Tp, size_t _Nm> template<typename _Tp, size_t _Nm>
......
// { dg-options "-D_GLIBCXX_DEBUG" }
// { dg-do compile { target c++20 } }
// Bug libstdc++/106212 - Code becomes non-constexpr with _GLIBCXX_DEBUG
#include <array>
struct A
{
constexpr A(int i) : e{i} {}
constexpr bool operator==(const A& a) const = default;
std::array<int, 1> e;
};
static_assert(A{1} != A{2}, "");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment