0

I am confused why the following didn't compile on clang++6.0 but works perfectly on G++7.x, both with -std=c++17.

std::variant<int, float> a;
a = 1;

This gives me the error on clang++6.0 for the following:

error: cannot cast 'std::variant<int, double>' to its private base class 
'std::__detail::__variant::_Variant_storage<true, int, double>'

return __get(std::in_place_index<_Np>, std::forward<_Variant>(__v)._M_u);
...

Is there anything wrong with the value assignment?

Jes
  • 2,614
  • 4
  • 25
  • 45
  • Have you tried `std::get<0>(a) = 1;` instead? – Ruks Aug 25 '18 at 04:05
  • `-stdlib=libc++`? Looks like an incompatibility between some versions of clang and some versions of libstdc++. – Marc Glisse Aug 25 '18 at 04:09
  • @MarcGlisse was fixed ages ago. clang++6.0.0 should be able to do this now (I just checked myself) OP needs to update his setup. Or at least use workaround for bug – Swift - Friday Pie Aug 25 '18 at 04:49
  • @Swift-FridayPie As far as I can tell from https://bugs.llvm.org/show_bug.cgi?id=33222 , there is a workaround in some versions of libstdc++, but clang still has the bug. – Marc Glisse Aug 25 '18 at 05:11
  • @MarcGlisse the issue is that it's not-a-bug., "wont-fix" kind, because devs do not support gcc-7.1+ yet. The workaround is purely a fix to header code of library if I recall right, to make it compatible with compiler: gcc and clang simply do not match in behavior. The distros of library I tried it with, already have the fix, I could't reproduce old problem with std::variant. – Swift - Friday Pie Aug 25 '18 at 07:42

0 Answers0