mpark / variant

C++17 `std::variant` for C++11/14/17
https://mpark.github.io/variant
Boost Software License 1.0
664 stars 87 forks source link

Support for pointers to incomplete types #34

Closed mgieseki closed 5 years ago

mgieseki commented 7 years ago

First of all, thank you for providing this implementation of std::variant. It's great to have a lightweight alternative to boost::variant available in C++11. I just stumbled over an issue with recursive type definitions, and I'm not sure whether it's a limitation of C++11 or the variant implementation. The following struct definition compiles fine with GCC's and Clang's C++17 support:

struct S {
    std::variant<
        std::map<int, S>*
    > var;
};

When replacing std::variant with mpark::variant, I get an error message regarding the incomplete type S of std::pair<int, S>::second. Is it possible to enhance your implementation so that this kind of recursive type definition compiles with mpark::variant under C++11 as well?

mpark commented 7 years ago

Thanks for the report! I just tried it out and confirmed the issue. It either looks like my fallback implementation of is_swappable is instantiating too eagerly, or I'm checking for is_swappable where I shouldn't be. I'm going to be attending CppCon this week, so I'll be sure to fix this after the conference!

mgieseki commented 7 years ago

Awesome. Thanks for the confirmation and for having a look into the issue. Have a great time at CppCon.

mpark commented 6 years ago

The following commits address this issue:

mgieseki commented 6 years ago

Great! Thanks for fixing this issue. It works flawlessly now.

cor3ntin commented 6 years ago

I'm experiencing something similar with gcc 7, seems to work with 8 https://godbolt.org/z/0fb-bV (also works if I use standard variant) Thanks!

mpark commented 5 years ago

The core of the issue here was that my implementation of invoke was instantiating too much. This is fixed by 5713032c68c6dad70a6a1d9f72b80c737c249a28