public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/104470] internal compiler error: Segmentation fault compiling std::variant with -std=c++20
Date: Thu, 10 Feb 2022 08:18:52 +0000	[thread overview]
Message-ID: <bug-104470-4-wEGEZ9x5XJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104470-4@http.gcc.gnu.org/bugzilla/>

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'

  parent reply	other threads:[~2022-02-10  8:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 18:25 [Bug c++/104470] New: " serpent7776 at gmail dot com
2022-02-10  1:09 ` [Bug c++/104470] " pinskia at gcc dot gnu.org
2022-02-10  6:02 ` pinskia at gcc dot gnu.org
2022-02-10  8:18 ` pinskia at gcc dot gnu.org [this message]
2022-04-22 11:57 ` max.kanold@nu-cost.com
2022-04-22 15:03 ` mpolacek at gcc dot gnu.org
2022-04-22 15:10 ` [Bug c++/104470] [10/11/12 Regression] " mpolacek at gcc dot gnu.org
2022-04-26 22:34 ` jason at gcc dot gnu.org
2022-04-29 21:25 ` [Bug c++/104470] [10/11/12/13 " cvs-commit at gcc dot gnu.org
2022-05-04 21:59 ` cvs-commit at gcc dot gnu.org
2022-05-15 16:29 ` [Bug c++/104470] [10/11/12 " cvs-commit at gcc dot gnu.org
2022-06-28 10:48 ` [Bug c++/104470] [10/11 " jakub at gcc dot gnu.org
2023-07-07 10:42 ` [Bug c++/104470] [11 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104470-4-wEGEZ9x5XJ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).