From: Jonathan Wakely <jwakely@redhat.com>
To: Glen Fernandes <glen.fernandes@gmail.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Implement std::to_address for C++2a
Date: Tue, 28 Nov 2017 14:57:00 -0000 [thread overview]
Message-ID: <20171128142454.GB31922@redhat.com> (raw)
In-Reply-To: <CAHVPgzksz9RcR_Ud=tPgG-DXoro3TPmssTrWOAv2G7a+uV3AvA@mail.gmail.com>
On 25/11/17 10:31 -0500, Glen Fernandes wrote:
>(Just a minor update to the last patch to use is_function_v<T> instead
>of is_function<T>::value)
>
>Implement std::to_address for C++2a
Thanks, Glen, I've committed this to trunk, with one small change to
fix the copyright dates in the new test, to be just 2017.
Because my new hobby is finding uses for if-constexpr, I think we
could have used the detection idiom to do it in a single overload, but
I don't see any reason to prefer that over your implementation:
template<typename _Ptr>
using __ptr_traits_to_address
= decltype(pointer_traits<_Ptr>::to_address(std::declval<_Ptr>()));
template<typename _Ptr>
constexpr auto
__to_address(const _Ptr& __ptr) noexcept
{
struct __nonesuch;
using type = __detected_or_t<__nonesuch, __ptr_traits_to_address, _Ptr>;
if constexpr (is_same_v<type, __nonesuch>)
return std::__to_address(__ptr.operator->());
else
return std::pointer_traits<_Ptr>::to_address(__ptr);
}
However, more importantly, both this form and yours fails for the
following test case, in two ways:
#include <memory>
struct P {
using F = void();
F* operator->() const noexcept { return nullptr; }
};
int main()
{
P p;
std::to_address(p);
}
Firstly, instantiating pointer_traits<P> fails a static assertion
(outside the immediate context, so not SFINAE-able):
In file included from /home/jwakely/gcc/8/include/c++/8.0.0/bits/stl_iterator.h:66:0,
from /home/jwakely/gcc/8/include/c++/8.0.0/bits/stl_algobase.h:67,
from /home/jwakely/gcc/8/include/c++/8.0.0/memory:62,
from toaddr.cc:1:
/home/jwakely/gcc/8/include/c++/8.0.0/bits/ptr_traits.h: In instantiation of âstruct std::pointer_traits<P>â:
/home/jwakely/gcc/8/include/c++/8.0.0/type_traits:2364:62: recursively required by substitution of âtemplate<class _Default, template<class ...> class _Op, class ... _Args> struct std::__detector<_Default, std::__void_t<_Op<_Args ...> >, _Op, _Args ...> [with _Default = std::__to_address(const _Ptr&) [with _Ptr = P]::__nonesuch; _Op = std::__ptr_traits_to_address; _Args = {P}]â
/home/jwakely/gcc/8/include/c++/8.0.0/type_traits:2364:62: required by substitution of âtemplate<class _Default, template<class ...> class _Op, class ... _Args> using __detected_or_t = typename std::__detected_or<_Default, _Op, _Args ...>::type [with _Default = std::__to_address(const _Ptr&) [with _Ptr = P]::__nonesuch; _Op = std::__ptr_traits_to_address; _Args = {P}]â
/home/jwakely/gcc/8/include/c++/8.0.0/bits/ptr_traits.h:169:78: required from âconstexpr auto std::__to_address(const _Ptr&) [with _Ptr = P]â
/home/jwakely/gcc/8/include/c++/8.0.0/bits/ptr_traits.h:200:31: required from âconstexpr auto std::to_address(const _Ptr&) [with _Ptr = P]â
toaddr.cc:12:20: required from here
/home/jwakely/gcc/8/include/c++/8.0.0/bits/ptr_traits.h:114:7: error: static assertion failed: pointer type defines element_type or is like SomePointer<T, Args>
static_assert(!is_same<element_type, __undefined>::value,
^~~~~~~~~~~~~
I'm not sure if this is a bug in our std::pointer_traits, or if the
standard requires the specialization of std::pointer_traits<P> to be
ill-formed (see [pointer.traits.types] p1). We have a problem if it
does require it, and either need to relax the requirements on
pointer_traits, or we need to alter the wording for to_address so that
it doesn't try to use pointer_traits when the specialization would be
ill-formed.
Secondly, if I remove that static_assert from <bits/ptr_traits.h> then
the test compiles, which is wrong, because it calls std::to_address on
a function pointer type. That should be ill-formed. The problem is
that the static_assert(!is_function_v<_Ptr>) is in std::to_address and
the implementation actually uses std::__to_address. So I think we want
the !is_function_v<_Ptr> check to be moved to the __to_address(_Ptr*)
overload.
next prev parent reply other threads:[~2017-11-28 14:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-25 18:48 Glen Fernandes
2017-11-28 14:57 ` Jonathan Wakely [this message]
2017-11-28 17:39 ` Glen Fernandes
2017-11-28 21:11 ` Jonathan Wakely
2017-11-29 10:00 ` Glen Fernandes
2017-11-30 15:10 ` Jonathan Wakely
-- strict thread matches above, loose matches on Subject: below --
2017-11-18 8:00 Glen Fernandes
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=20171128142454.GB31922@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=glen.fernandes@gmail.com \
--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).