https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94209
Bug ID: 94209 Summary: std::variant<int> can't be initialized from unsigned int with gcc trunk Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: romain.geissler at amadeus dot com Target Milestone: --- Hi, With gcc trunk the following fails, while it was working with gcc 8 and 9. I think (but am not sure) the implicit conversion from unsigned int to int shall be allowed. #include <variant> void f() { std::variant<int>{1}; // works std::variant<int>{std::in_place_type_t<int>(), 1}; // works std::variant<int>{std::in_place_type_t<int>(), 1u}; // works std::variant<int>{1u}; // fails }; <source>: In function 'void f()': <source>:8:25: error: no matching function for call to 'std::variant<int>::variant(<brace-enclosed initializer list>)' 8 | std::variant<int>{1u}; // fails | ^ In file included from <source>:1: /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1407:2: note: candidate: 'template<long unsigned int _Np, class _Up, class ... _Args, class _Tp, class> constexpr std::variant<_Types>::variant(std::in_place_index_t<_Np>, std::initializer_list<_Up>, _Args&& ...) [with long unsigned int _Np = _Np; _Up = _Up; _Args = {_Args ...}; _Tp = _Tp; <template-parameter-2-5> = <template-parameter-1-5>; _Types = {int}]' 1407 | variant(in_place_index_t<_Np>, initializer_list<_Up> __il, | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1407:2: note: template argument deduction/substitution failed: <source>:8:25: note: mismatched types 'std::in_place_index_t<_Idx>' and 'unsigned int' 8 | std::variant<int>{1u}; // fails | ^ In file included from <source>:1: /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1396:2: note: candidate: 'template<long unsigned int _Np, class ... _Args, class _Tp, class> constexpr std::variant<_Types>::variant(std::in_place_index_t<_Np>, _Args&& ...) [with long unsigned int _Np = _Np; _Args = {_Args ...}; _Tp = _Tp; <template-parameter-2-4> = <template-parameter-1-4>; _Types = {int}]' 1396 | variant(in_place_index_t<_Np>, _Args&&... __args) | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1396:2: note: template argument deduction/substitution failed: <source>:8:25: note: mismatched types 'std::in_place_index_t<_Idx>' and 'unsigned int' 8 | std::variant<int>{1u}; // fails | ^ In file included from <source>:1: /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1386:2: note: candidate: 'template<class _Tp, class _Up, class ... _Args, class> constexpr std::variant<_Types>::variant(std::in_place_type_t<_Tp>, std::initializer_list<_Up>, _Args&& ...) [with _Tp = _Tp; _Up = _Up; _Args = {_Args ...}; <template-parameter-2-4> = <template-parameter-1-4>; _Types = {int}]' 1386 | variant(in_place_type_t<_Tp>, initializer_list<_Up> __il, | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1386:2: note: template argument deduction/substitution failed: <source>:8:25: note: mismatched types 'std::in_place_type_t<_Tp>' and 'unsigned int' 8 | std::variant<int>{1u}; // fails | ^ In file included from <source>:1: /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1376:2: note: candidate: 'template<class _Tp, class ... _Args, class> constexpr std::variant<_Types>::variant(std::in_place_type_t<_Tp>, _Args&& ...) [with _Tp = _Tp; _Args = {_Args ...}; <template-parameter-2-3> = <template-parameter-1-3>; _Types = {int}]' 1376 | variant(in_place_type_t<_Tp>, _Args&&... __args) | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1376:2: note: template argument deduction/substitution failed: <source>:8:25: note: mismatched types 'std::in_place_type_t<_Tp>' and 'unsigned int' 8 | std::variant<int>{1u}; // fails | ^ In file included from <source>:1: /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1366:2: note: candidate: 'template<class _Tp, class, class, class _Tj, class> constexpr std::variant<_Types>::variant(_Tp&&) [with _Tp = _Tp; <template-parameter-2-2> = <template-parameter-1-2>; <template-parameter-2-3> = <template-parameter-1-3>; _Tj = _Tj; <template-parameter-2-5> = <template-parameter-1-5>; _Types = {int}]' 1366 | variant(_Tp&& __t) | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1366:2: note: template argument deduction/substitution failed: /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant: In substitution of 'template<class ... _Types> template<class _Tp, class> using __accepted_type = std::variant<_Types>::__to_type<__accepted_index<_Tp> > [with _Tp = unsigned int&&; <template-parameter-2-2> = void; _Types = {int}]': /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1362:9: required from here /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1332:8: error: no type named 'type' in 'struct std::enable_if<false, void>' 1332 | using __accepted_type = __to_type<__accepted_index<_Tp>>; | ^~~~~~~~~~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1354:7: note: candidate: 'constexpr std::variant<_Types>::variant(std::variant<_Types>&&) [with _Types = {int}]' 1354 | variant(variant&&) = default; | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1354:15: note: no known conversion for argument 1 from 'unsigned int' to 'std::variant<int>&&' 1354 | variant(variant&&) = default; | ^~~~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1353:7: note: candidate: 'constexpr std::variant<_Types>::variant(const std::variant<_Types>&) [with _Types = {int}]' 1353 | variant(const variant& __rhs) = default; | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1353:30: note: no known conversion for argument 1 from 'unsigned int' to 'const std::variant<int>&' 1353 | variant(const variant& __rhs) = default; | ~~~~~~~~~~~~~~~^~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1352:7: note: candidate: 'constexpr std::variant<_Types>::variant() [with _Types = {int}]' 1352 | variant() = default; | ^~~~~~~ /opt/compiler-explorer/gcc-trunk-20200317/include/c++/10.0.1/variant:1352:7: note: candidate expects 0 arguments, 1 provided Compiler returned: 1 Cheers, Romain