This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3, patch, variant] user-defined operator& and std::variant
- From: Tim Shen <timshen at google dot com>
- To: Mikhail Strelnikov <mikhail dot strelnikov at gmail dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 5 Sep 2016 12:44:50 -0700
- Subject: Re: [v3, patch, variant] user-defined operator& and std::variant
- Authentication-results: sourceware.org; auth=none
- References: <CAAihzV+nO8URZntPsNQG5udZEkUrKm3YQKwT=D5mB7qGTF7AYA@mail.gmail.com>
On Sat, Sep 3, 2016 at 12:46 PM, Mikhail Strelnikov wrote:
> Hello,
>
> Following code does not compile,
>
> #include <variant>
>
> namespace n
> {
> template<typename T>
> void operator&(T) {}
> struct s{};
> }
>
> int main()
> {
> std::variant<n::s> v;
> std::get<n::s>(v);
> }
>
> error: include/c++/7.0.0/variant:315:4: error: invalid static_cast
>
> diff -r -u a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
> --- a/libstdc++-v3/include/std/variant 2016-08-26 13:34:30.823029400 +0300
> +++ b/libstdc++-v3/include/std/variant 2016-09-03 18:01:26.431299300 +0300
> @@ -312,7 +312,7 @@
> _M_storage() const
> {
> return const_cast<void*>(
> - static_cast<const void*>(&_M_first._M_storage));
> + static_cast<const void*>(std::__addressof(_M_first._M_storage)));
> }
>
> union
Thanks for the patch! Tested on x86_64-linux-gnu and committed as r239996.
I changed std::__addressof to std::addressof since it's standardized
since C++11.
--
Regards,
Tim Shen