From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: "libstdc++" <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: PR libstdc++/78420 Make std::less etc. yield total order for pointers
Date: Sun, 18 Mar 2018 10:27:00 -0000 [thread overview]
Message-ID: <CAH6eHdQLgFMTMvA+o-ti3ssOgVa8AA-4M1vS2nwnd-Uk6WAsnQ@mail.gmail.com> (raw)
In-Reply-To: <CAH6eHdRRjYaYeGwZMWQpbAf-bh_r+CygDE7KB_whw1vAfzxK_g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]
On 14 March 2018 at 23:01, Jonathan Wakely wrote:
> Here's a very different patch. This gets rid of the __ptr_rel_ops and
> just puts the special handling for pointers directly in the
> std::less<_Tp*> etc. specializations. Then std::less<void> uses
> std::less<P*> for some pointer type P*. I've also added a ton of ugly
> metaprogramming to detect the "if the call operator calls a built-in
> operator comparing pointers" condition. The idea is borrowed from
> Casey Carter and Eric Niebler's Ranges work, but basically it checks
> if operator<(T,U) or T.operator<(U) can be called, and if not the
> comparison must be using a built-in operator. If both T and U are
> convertible to pointers (specifically, to const volatile void* which
> is the most accepting of all pointers) then we assume we're using a
> built-in operator comparing pointers, and delegate to std::less<const
> volatile void*>, which ensures a total order.
>
> Tested powerpc64le-linux, committed to trunk. This fixes a regression,
> but I'm not sure about backporting it yet, I haven't even tried
> testing it on the branches.
This adjusts the new test to avoid using 'auto' so it works as C++98 too.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2582 bytes --]
commit be039c0c67a6d18ddeb86bddc50cd9704a120f75
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Mar 17 13:35:50 2018 +0000
Fix new test that fails in C++98 mode
* testsuite/20_util/function_objects/comparisons_pointer.cc: Adjust
to compile as C++98.
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc b/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc
index 6b2b8be0f51..aad0bc3dd2e 100644
--- a/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc
+++ b/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc
@@ -27,7 +27,7 @@ int a[8];
void
test01()
{
- auto p = a + 8;
+ int* p = a + 8;
std::greater<int*> gt;
std::stringstream ss;
@@ -44,7 +44,7 @@ test01()
ss.str("");
ss.clear();
sum = 0;
- auto p2 = a + 8;
+ int* p2 = a + 8;
std::greater<> gt2;
ss << gt2(p2, b) << ' ' << gt2(b, p2) << ' ' << (!gt2(p2, b) && !gt2(b, p2));
while (ss >> n)
@@ -59,7 +59,7 @@ test01()
void
test02()
{
- auto p = a + 8;
+ int* p = a + 8;
std::less<int*> lt;
std::stringstream ss;
@@ -76,7 +76,7 @@ test02()
ss.str("");
ss.clear();
sum = 0;
- auto p2 = a + 8;
+ int* p2 = a + 8;
std::less<> lt2;
ss << lt2(p2, b) << ' ' << lt2(b, p2) << ' ' << (!lt2(p2, b) && !lt2(b, p2));
while (ss >> n)
@@ -91,7 +91,7 @@ test02()
void
test03()
{
- auto p = a + 8;
+ int* p = a + 8;
std::greater_equal<int*> ge;
std::stringstream ss;
@@ -109,7 +109,7 @@ test03()
ss.str("");
ss.clear();
sum = 0;
- auto p2 = a + 8;
+ int* p2 = a + 8;
std::greater_equal<> ge2;
ss << !ge2(p2, b) << ' ' << !ge2(b, p2) << ' ' << (ge2(p2, b) && ge2(b, p2));
while (ss >> n)
@@ -125,7 +125,7 @@ test03()
void
test04()
{
- auto p = a + 8;
+ int* p = a + 8;
std::less_equal<int*> le;
std::stringstream ss;
@@ -143,7 +143,7 @@ test04()
ss.str("");
ss.clear();
sum = 0;
- auto p2 = a + 8;
+ int* p2 = a + 8;
std::less_equal<> le2;
ss << !le2(p2, b) << ' ' << !le2(b, p2) << ' ' << (le2(p2, b) && le2(b, p2));
while (ss >> n)
@@ -167,7 +167,7 @@ void
test05()
{
std::less<const X*> lt;
- auto p = y + 4;
+ X* p = y + 4;
std::stringstream ss;
ss << lt(x, p) << ' ' << lt(p, x) << ' ' << (!lt(p, x) && !lt(x, p));
int sum = 0;
@@ -183,7 +183,7 @@ test05()
ss.str("");
ss.clear();
sum = 0;
- auto p2 = y + 4;
+ X* p2 = y + 4;
std::less<> lt2;
ss << lt2(x, p2) << ' ' << lt2(p2, x) << ' ' << (!lt2(x, p2) && !lt2(p2, x));
while (ss >> n)
next prev parent reply other threads:[~2018-03-17 13:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-09 0:41 Jonathan Wakely
2018-03-13 16:30 ` Jonathan Wakely
2018-03-14 23:27 ` Jonathan Wakely
2018-03-18 10:27 ` Jonathan Wakely [this message]
2018-03-22 14:27 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH6eHdQLgFMTMvA+o-ti3ssOgVa8AA-4M1vS2nwnd-Uk6WAsnQ@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).