public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94209] New: std::variant<int> can't be initialized from unsigned int with gcc trunk
@ 2020-03-17 23:31 romain.geissler at amadeus dot com
  2020-03-18  0:29 ` [Bug libstdc++/94209] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: romain.geissler at amadeus dot com @ 2020-03-17 23:31 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/94209] std::variant<int> can't be initialized from unsigned int with gcc trunk
  2020-03-17 23:31 [Bug libstdc++/94209] New: std::variant<int> can't be initialized from unsigned int with gcc trunk romain.geissler at amadeus dot com
@ 2020-03-18  0:29 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-18  0:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94209

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is the expected behaviour because gcc-10 implements
http://wg21.link/p0608r3

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-18  0:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 23:31 [Bug libstdc++/94209] New: std::variant<int> can't be initialized from unsigned int with gcc trunk romain.geissler at amadeus dot com
2020-03-18  0:29 ` [Bug libstdc++/94209] " redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).