public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dangelog at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/96416] to_address() is broken by static_assert in pointer_traits
Date: Sat, 27 Mar 2021 16:53:05 +0000	[thread overview]
Message-ID: <bug-96416-4-g1scy0NxsB@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96416-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96416

--- Comment #14 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
Hello,

(In reply to Glen Joseph Fernandes from comment #11)
> > if it can never be used.
> 
> You're misunderstanding.   to_address(p) requires that pointer_traits<P> is
> valid. It just doesn't need to have a to_address member function.

Thank you for clarifying this. I think the wording in the standard is very
unfortunate, but combined with the realization that pointer_traits isn't
SFINAE-friendly, then it's the only intended meaning.



> If (for contiguous iterators, which came later) you want pointer_traits<X>
> to be valid even when X does not have element_type, that is a design change
> to pointer_traits.

One might claim that pointer_traits should become SFINAE-friendly (like C++17's
iterator_traits), but sure, that's a different design question and not
necessarily needed here.


(In reply to Jonathan Wakely from comment #12)
> (In reply to Giuseppe D'Angelo from comment #10)
> > (By the way, finding this bug is quite hard. Could "address_of" be changed
> > to "to_address" , in the bug description?
> 
> Done.

Thank you!



(In reply to Arthur O'Dwyer from comment #13)
> > And are you recommending that everyone who defines their custom contiguous
> > iterators specializes pointer_traits for them? Call it _quite_ annoying...
> 
> Definitely not! When you define a contiguous iterator type, you should just
> give it a sixth nested typedef alongside the other five (or three in C++20):
> `using element_type = value_type;`. This enables contiguous-iterator
> machinery.
> See
> https://stackoverflow.com/questions/65712091/in-c20-how-do-i-write-a-
> contiguous-iterator/66050521#66050521


This gets evil really quick: the presence of both value_type and element_type
in an contiguous iterator will make you smash face-first against LWG3446, which
isn't implemented in GCC 10 AFAICS.

https://cplusplus.github.io/LWG/issue3446


What's more, the accepted resolution wording for it appears to be wrong:


  template<classhas-member-value-type T>
    requires has-member-element-type<T> &&
             same_as<remove_cv_t<typename T::element_type>,
remove_cv_t<typename T::value_type>>
  struct indirectly_readable_traits<T>
    : cond-value-type<typename T::value_type> { };


For const iterators, value_type is actually different from element_type (!).
Thankfully libstdc++ seems to have considered this as a non-standard extension,
https://github.com/gcc-mirror/gcc/commit/186aa6304570e15065f31482e9c27326a3a6679f 


To summarize:

* should a wording defect be raised against std::to_address(Ptr), to state that
pointer_traits<Ptr> being well-formed is actually a prerequisite?

* should LWG3446's resolution be amended?

* if there's going to be a GCC 10.3, is the commit above solving LWG3446 going
to be cherry-picked into it? Otherwise, either one blacklists GCC 10, or has to
specialize pointer_traits there as a workaround (?).


Thank you all for the insightful comments.

  parent reply	other threads:[~2021-03-27 16:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-02  4:17 [Bug libstdc++/96416] New: address_of() " whatwasthataddress at gmail dot com
2020-08-03 12:58 ` [Bug libstdc++/96416] " redi at gcc dot gnu.org
2020-08-03 15:34 ` whatwasthataddress at gmail dot com
2020-08-03 15:38 ` redi at gcc dot gnu.org
2020-11-11 17:46 ` redi at gcc dot gnu.org
2020-11-11 18:52 ` redi at gcc dot gnu.org
2020-11-11 19:10 ` redi at gcc dot gnu.org
2020-11-11 20:05 ` glenjofe at gmail dot com
2020-11-11 20:40 ` redi at gcc dot gnu.org
2020-11-11 20:41 ` redi at gcc dot gnu.org
2021-03-26 14:19 ` dangelog at gmail dot com
2021-03-26 14:45 ` dangelog at gmail dot com
2021-03-26 23:44 ` glenjofe at gmail dot com
2021-03-27  0:48 ` [Bug libstdc++/96416] to_address() " redi at gcc dot gnu.org
2021-03-27  1:41 ` arthur.j.odwyer at gmail dot com
2021-03-27 16:53 ` dangelog at gmail dot com [this message]
2021-03-27 19:46 ` redi at gcc dot gnu.org
2021-03-29  3:08 ` glenjofe at gmail dot com
2021-04-20 20:11 ` redi at gcc dot gnu.org
2021-04-21  8:45 ` dangelog at gmail dot com
2021-08-05 22:55 ` gcc-bugs at marehr dot dialup.fu-berlin.de
2021-09-28 14:00 ` [Bug libstdc++/96416] [DR 3545] " redi at gcc dot gnu.org
2021-11-25 23:12 ` cvs-commit at gcc dot gnu.org
2021-11-26 17:46 ` cvs-commit at gcc dot gnu.org
2021-11-26 17:52 ` redi at gcc dot gnu.org
2021-12-09  1:24 ` whatwasthataddress at gmail dot com
2022-06-28 10:41 ` jakub at gcc dot gnu.org
2023-07-07  9:00 ` rguenth at gcc dot gnu.org

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=bug-96416-4-g1scy0NxsB@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).