Closed ligfx closed 4 years ago
Hi @ligfx , Thanks for your message.
I think a relevant remark related to C++11 and later is No perfect forwarding here in order to simplify code.
Used wrong selection of nonstd::variant:
Trying on Godbolt, using clang 7.0.0, -std=c++17 (the first that successfully compiles std::visit(myvisitor(), v);
) also successfully compiles for nonstd::variant
.
So it seems more specific information is needed to assess what it is you run into, like compiler version and compilation flags.
Hi @martinmoene, I don't think perfect forwarding is related to this. There are two places in the code that explicitly try to default construct the return type, regardless of which version of C++: https://github.com/martinmoene/variant-lite/blob/a0a1be0d32066ca68cec3d351a71f337637d9ddf/include/nonstd/variant.hpp#L1922 and https://github.com/martinmoene/variant-lite/blob/a0a1be0d32066ca68cec3d351a71f337637d9ddf/include/nonstd/variant.hpp#L2109
When the return type is a const reference, it can't be default constructed.
Since a visitor is required to match all possible alternatives, that code should never be called, but the compiler doesn't like it anyways. What do you think about changing those lines to abort()
or std::terminate
? Something that the compiler knows won't return.
Thanks @ligfx , will look into this later.
Great, thanks!
Example of the issue:
The STL version of variant compiles and works. nonstd::variant throws a compile error: