public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/101715] [11 Regression] ICE with noexcept and canonical types differ for identical types
Date: Mon, 24 Jan 2022 21:26:16 +0000	[thread overview]
Message-ID: <bug-101715-4-FkXHDSMhDT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101715-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #21 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:9f2201bf48e828a7072616fff9dbd64367dcea30

commit r11-9508-g9f2201bf48e828a7072616fff9dbd64367dcea30
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Jan 24 16:24:47 2022 -0500

    c++: ICE with noexcept and canonical types [PR101715]

    This is a "canonical types differ for identical types" ICE, which started
    with r11-4682.  It's a bit tricky to explain.  Consider:

      template <typename T> struct S {
        S<T> bar() noexcept(T::value);  // #1
        S<T> foo() noexcept(T::value);  // #2
      };

      template <typename T> S<T> S<T>::foo() noexcept(T::value) {}  // #3

    We ICE because #3 and #2 have the same type, but their canonical types
    differ: TYPE_CANONICAL (#3) == #2 but TYPE_CANONICAL (#2) == #1.

    The member functions #1 and #2 have the same type.  However, since their
    noexcept-specifier is deferred, when parsing them, we create a variant for
    both of them, because DEFERRED_PARSE cannot be compared.  In other words,
    build_cp_fntype_variant's

      tree v = TYPE_MAIN_VARIANT (type);
      for (; v; v = TYPE_NEXT_VARIANT (v))
        if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
          return v;

    will *not* find an existing variant when creating a method_type for #2, so
we
    have to create a new one.

    But then we perform delayed parsing and call
fixup_deferred_exception_variants
    for #1 and #2.  f_d_e_v will replace TYPE_RAISES_EXCEPTIONS with the newly
    parsed noexcept-specifier.  It also sets TYPE_CANONICAL (#2) to #1.  Both
    noexcepts turned out to be the same, so now we have two equivalent variants
in
    the list!  I.e.,

    +-----------------+      +-----------------+      +-----------------+
    |      main       |      |      #2         |      |      #1         |
    | S S::<T379>(S*) |----->| S S::<T37c>(S*) |----->| S S::<T37a>(S*)
|----->NULL
    |    -            |      |  noex(T::value) |      |  noex(T::value) |
    +-----------------+      +-----------------+      +-----------------+

    Then we get to #3.  As for #1 and #2, grokdeclarator calls
build_memfn_type,
    which ends up calling build_cp_fntype_variant, which will use the loop
    above to look for an existing variant.  The first one that matches
    cp_check_qualified_type will be used, so we use #2 rather than #1, and the
    TYPE_CANONICAL mismatch follows.  Hopefully that makes sense.

    As for the fix, I didn't think I could rewrite the method_type #2 with #1
    because the type may have escaped via decltype.  So my approach is to
    elide #2 from the list, so when looking for a matching variant, we always
    find #1 (#2 remains live though, which admittedly sounds sort of dodgy).

            PR c++/101715

    gcc/cp/ChangeLog:

            * tree.c (fixup_deferred_exception_variants): Remove duplicate
            variants after parsing the exception specifications.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/noexcept72.C: New test.
            * g++.dg/cpp0x/noexcept73.C: New test.

    (cherry picked from commit 3abcbf243239f9576a60f4ce7f8ee4b3fa14784b)

  parent reply	other threads:[~2022-01-24 21:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-01 17:32 [Bug c++/101715] New: compiler ice when uses a GCC cross compiler to canadian compile LLVM libc++ unlvsur at live dot com
2021-08-01 17:44 ` [Bug c++/101715] " pinskia at gcc dot gnu.org
2021-08-01 19:11 ` unlvsur at live dot com
2021-08-01 19:12 ` unlvsur at live dot com
2021-08-01 20:50 ` pinskia at gcc dot gnu.org
2021-08-01 22:41 ` pinskia at gcc dot gnu.org
2021-08-01 22:43 ` [Bug c++/101715] [11/12 Regression] " pinskia at gcc dot gnu.org
2021-08-01 23:53 ` [Bug c++/101715] [11/12 Regression] ICE with noexcept and canonical types differ for identical types caused by r12-1824 hjl.tools at gmail dot com
2021-08-02  1:58 ` pinskia at gcc dot gnu.org
2021-08-02  8:44 ` rguenth at gcc dot gnu.org
2021-08-02 16:02 ` [Bug c++/101715] [11/12 Regression] ICE with noexcept and canonical types differ for identical types redi at gcc dot gnu.org
2021-08-02 16:38 ` mpolacek at gcc dot gnu.org
2021-11-04  8:52 ` pinskia at gcc dot gnu.org
2021-11-04  8:55 ` marxin at gcc dot gnu.org
2021-11-04 15:01 ` mpolacek at gcc dot gnu.org
2021-11-16 21:34 ` pinskia at gcc dot gnu.org
2021-12-01  9:38 ` pinskia at gcc dot gnu.org
2021-12-28 13:46 ` slyfox at gcc dot gnu.org
2022-01-13 21:01 ` mpolacek at gcc dot gnu.org
2022-01-15  0:24 ` mpolacek at gcc dot gnu.org
2022-01-15 21:30 ` slyfox at gcc dot gnu.org
2022-01-21 18:12 ` cvs-commit at gcc dot gnu.org
2022-01-21 18:14 ` [Bug c++/101715] [11 " mpolacek at gcc dot gnu.org
2022-01-24 21:26 ` cvs-commit at gcc dot gnu.org [this message]
2022-01-24 21:26 ` mpolacek 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-101715-4-FkXHDSMhDT@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).