This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3, patch, variant] user-defined operator& and std::variant


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]