public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "Daniel Krügler" <daniel.kruegler@gmail.com>
Cc: libstdc++ <libstdc++@gcc.gnu.org>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Implement LWG 2686, hash<error_condition>
Date: Tue, 07 May 2019 15:27:00 -0000	[thread overview]
Message-ID: <20190507152737.GW2599@redhat.com> (raw)
In-Reply-To: <20190504143628.GL2599@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2404 bytes --]

On 04/05/19 15:36 +0100, Jonathan Wakely wrote:
>On 03/05/19 23:42 +0100, Jonathan Wakely wrote:
>>On 23/03/17 17:49 +0000, Jonathan Wakely wrote:
>>>On 12/03/17 13:16 +0100, Daniel Krügler wrote:
>>>>The following is an *untested* patch suggestion, please verify.
>>>>
>>>>Notes: My interpretation is that hash<error_condition> should be
>>>>defined outside of the _GLIBCXX_COMPATIBILITY_CXX0X block, please
>>>>double-check that course of action.
>>>
>>>That's right.
>>>
>>>>I noticed that the preexisting hash<error_code> did directly refer to
>>>>the private members of error_code albeit those have public access
>>>>functions. For consistency I mimicked that existing style when
>>>>implementing hash<error_condition>.
>>>
>>>I see no reason for that, so I've removed the friend declaration and
>>>used the public member functions.
>>
>>I'm going to do the same for hash<error_code> too. It can also use the
>>public members instead of being a friend.
>>
>>
>>>Although this is a DR, I'm treating it as a new C++17 feature, so I've
>>>adjusted the patch to only add the new specialization for C++17 mode.
>>>We're too close to the GCC 7 release to be adding new things to the
>>>default mode, even minor things like this. After GCC 7 is released we
>>>can revisit it and decide if we want to enable it for all modes.
>>
>>We never revisited that, and it's still only enabled for C++17 and up.
>>I guess that's OK, but we could enabled it for C++11 and 14 on trunk
>>if we want. Anybody care enough to argue for that?
>>
>>>Here's what I've tested and will be committing.
>>>
>>>
>>
>>>commit 90ca0fd91f5c65af370beb20af06bdca257aaf63
>>>Author: Jonathan Wakely <jwakely@redhat.com>
>>>Date:   Thu Mar 23 11:47:39 2017 +0000
>>>
>>>  Implement LWG 2686, std::hash<error_condition>, for C++17
>>>  2017-03-23  Daniel Kruegler  <daniel.kruegler@gmail.com>
>>>  	Implement LWG 2686, Why is std::hash specialized for error_code,
>>>  	but not error_condition?
>>>  	* include/std/system_error (hash<error_condition>): Define for C++17.
>>>  	* testsuite/20_util/hash/operators/size_t.cc (hash<error_condition>):
>>>  	Instantiate test for error_condition.
>>>  	* testsuite/20_util/hash/requirements/explicit_instantiation.cc
>>>  	(hash<error_condition>): Instantiate hash<error_condition>.

I'm adding a similar test for hash<error_code> too.

Tested powerpc64le-linux, committing to trunk shortly.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2143 bytes --]

commit 4034dddf0dbfc20ff9069602a419a95b09de20f6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue May 7 11:09:00 2019 +0100

    Add test for std::hash<std::error_code>
    
    Copied from 19_diagnostics/error_condition/hash.cc added recently.
    
            * testsuite/19_diagnostics/error_code/hash.cc: New test.

diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/hash.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/hash.cc
new file mode 100644
index 00000000000..2014e676878
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/hash.cc
@@ -0,0 +1,50 @@
+// Copyright (C) 2019 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 run { target c++11 } }
+
+#include <system_error>
+#include <testsuite_hooks.h>
+
+struct error_cat : std::error_category
+{
+  error_cat(std::string s) : _name(s) { }
+  std::string _name;
+  const char* name() const noexcept override { return _name.c_str(); }
+  std::string message(int) const override { return "error"; }
+};
+
+void
+test01()
+{
+  std::hash<std::error_code> h;
+  error_cat kitty("kitty"), moggy("moggy");
+  std::error_code cond1(99, kitty);
+  VERIFY( h(cond1) == h(cond1) );
+  std::error_code cond2(99, kitty);
+  VERIFY( h(cond1) == h(cond2) );
+  std::error_code cond3(88, kitty);
+  VERIFY( h(cond1) != h(cond3) );
+  std::error_code cond4(99, moggy);
+  VERIFY( h(cond1) != h(cond4) );
+}
+
+int
+main()
+{
+  test01();
+}

      parent reply	other threads:[~2019-05-07 15:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 12:16 Daniel Krügler
2017-03-21 21:26 ` Daniel Krügler
2017-03-23 17:50 ` Jonathan Wakely
     [not found]   ` <20190503224255.GI2599@redhat.com>
2019-05-04 14:36     ` Jonathan Wakely
2019-05-07  9:06       ` Christophe Lyon
2019-05-07  9:37         ` Jonathan Wakely
2019-05-07 10:07           ` Jonathan Wakely
2019-05-07 12:22             ` Christophe Lyon
2019-05-09 14:43               ` Szabolcs Nagy
2019-05-09 15:17                 ` Jonathan Wakely
2019-05-29 11:09                   ` Szabolcs Nagy
2019-05-07 15:27       ` Jonathan Wakely [this message]

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=20190507152737.GW2599@redhat.com \
    --to=jwakely@redhat.com \
    --cc=daniel.kruegler@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).