https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102912
Bug ID: 102912 Summary: Not full support of const arguments in std::variant Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program is valid: ``` #include <string> #include <variant> using S = std::variant<const int, const std::string>; int main() { S s(1); S u = s; S v("abc"); S w = v; } ``` but its compilation in GCC results in a long error: ``` In file included from <source>:2: /opt/compiler-explorer/gcc-trunk-20211024/include/c++/12.0.0/variant: In instantiation of 'constexpr std::__detail::__variant::_Variadic_union<_First, _Rest ...>::_Variadic_union(std::in_place_index_t<_Np>, _Args&& ...) [with long unsigned int _Np = 1; _Args = {const int&}; _First = const std::__cxx11::basic_string<char>; _Rest = {}]': /opt/compiler-explorer/gcc-trunk-20211024/include/c++/12.0.0/variant:409:4: required from 'constexpr std::__detail::__variant::_Variadic_union<_First, _Rest ...>::_Variadic_union(std::in_place_index_t<_Np>, _Args&& ...) [with long unsigned int _Np = 2; _Args = {const int&}; _First = const int; _Rest = {const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]' /opt/compiler-explorer/gcc-trunk-20211024/include/c++/12.0.0/bits/stl_construct.h:119:7: required from 'constexpr void std::_Construct(_Tp*, _Args&& ...) [with _Tp = std::__detail::__variant::_Variadic_union<const int, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >; _Args = {const std::in_place_index_t<2>&, const int&}]' ... Demo: https://gcc.godbolt.org/z/ocajj3aao Related discussion: https://stackoverflow.com/q/69696170/7325599 ```