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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-02-10
           Keywords|needs-reduction             |ice-on-invalid-code
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, reduced:
template<typename _Types>
class variant
{
        template<typename _Tp>
                static constexpr int __accepted_index = 0;
        template<int _Np>
                using __to_type = int;
        template<typename _Tp>
                using __accepted_type = __to_type<__accepted_index<_Tp>>;
        template<typename _Tp, typename _Tj = __accepted_type<_Tp>>
                variant(_Tp __t)  { }
};
template <typename T>
struct Foo
{
        T value;
};
template <typename T>
using V = variant<Foo<T>>;
V e = Foo{1};


---- CUT ----
So I think in the end this is invalid code as the compiler cannot deduce
template arguments for V, even though you would think it should.

Note clang does not implement a few C++20 deduction support yet so it rejects
it for a few other reasons (alias deduction).

But MSVC rejects the original code with the following error message (which
seems reasonable):

<source>(21): error C2641: cannot deduce template arguments for 'V'
<source>(21): error C2783: 'std::variant<Foo<T>,Bar<T>> std::variant(_Ty &&)
noexcept(<expr>)': could not deduce template argument for 'T'
C:/data/msvc/14.31.31103-Pre/include\variant(1024): note: see declaration of
'std::variant'
<source>(21): error C2783: 'std::variant<Foo<T>,Bar<T>> std::variant(_Ty &&)
noexcept(<expr>)': could not deduce template argument for 'T'
C:/data/msvc/14.31.31103-Pre/include\variant(1024): note: see declaration of
'std::variant'
<source>(21): error C2780: 'std::variant<Foo<T>,Bar<T>> std::variant(void)
noexcept(<expr>)': expects 0 arguments - 1 provided
C:/data/msvc/14.31.31103-Pre/include\variant(1014): note: see declaration of
'std::variant'
<source>(21): error C2784: 'std::variant<Foo<T>,Bar<T>>
std::variant(std::variant<Foo<T>,Bar<T>>)': could not deduce template argument
for 'std::variant<Foo<T>,Bar<T>>' from 'Foo<const char *>'
C:/data/msvc/14.31.31103-Pre/include\variant(1004): note: see declaration of
'std::variant'
<source>(21): error C2784: 'std::variant<Foo<T>,Bar<T>>
std::variant(std::variant<Foo<T>,Bar<T>>)': could not deduce template argument
for 'std::variant<Foo<T>,Bar<T>>' from 'Foo<const char *>'
C:/data/msvc/14.31.31103-Pre/include\variant(1004): note: see declaration of
'std::variant'

Reply via email to