mapbox / variant

C++11/C++14 Variant
BSD 3-Clause "New" or "Revised" License
371 stars 101 forks source link

Unexpected behavior when initializing with const references #112

Closed jfirebaugh closed 8 years ago

jfirebaugh commented 8 years ago

Consider the following:

using value = mapbox::util::variant<bool, uint64_t>;

uint64_t u(1234);
assert(value(u).is<uint64_t>()); // passes

uint64_t& ur(u);
assert(value(ur).is<uint64_t>()); // passes

uint64_t const& ucr(u);
assert(value(ucr).is<uint64_t>()); // fails, it's bool!

The last assertion should not fail.

cc @artemp @joto @springmeyer

artemp commented 8 years ago

@jfirebaugh - fixed and test added (b3a002d + c511b2f) In value_traits both reference and const specifier needs stripping to correctly calculate direct_type matching.

/cc @springmeyer @joto