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++/97034] [11 Regression] ICE on C++20 code: gcc_assert failure in return type deduction (gcc/cp/pt.c:26984 in type_dependent_expression_p(tree_node*))
Date: Wed, 03 Mar 2021 14:53:36 +0000	[thread overview]
Message-ID: <bug-97034-4-anryphMGOm@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97034-4@http.gcc.gnu.org/bugzilla/>

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

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

https://gcc.gnu.org/g:1dabbfb0f4a9fbdc77e1ea4db7302586f00895e1

commit r11-7483-g1dabbfb0f4a9fbdc77e1ea4db7302586f00895e1
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Feb 12 12:21:15 2021 -0500

    c++: ICE with deduction guide in checking type-dep [PR99009, PR97034]

    We represent deduction guides with FUNCTION_DECLs, but they are built
    without DECL_CONTEXT, leading to an ICE in type_dependent_expression_p
    on the assert that the type of a function template with no dependent
    (innermost!) template arguments must be non-dependent.  Consider the
    attached class-deduction79.C: we create a deduction guide:

      template<class T> G(T)-> E<Z>::G<T>

    we deduce T and create a partial instantiation:

      G(T) -> E<Z>::G<T> [with T = int]

    And then do_class_deduction wants to create a CALL_EXPR from the above
    using build_new_function_call -> build_over_call which calls mark_used
    -> maybe_instantiate_noexcept -> type_dependent_expression_p.

    There, the innermost template arguments are non-dependent (<int>), but
    the fntype is dependent -- the return type is a TYPENAME_TYPE, and
    since we have no DECL_CONTEXT, this check holds:

      /* Otherwise, if the function decl isn't from a dependent scope, it can't
be
         type-dependent.  Checking this is important for functions with auto
return
         type, which looks like a dependent type.  */
      if (TREE_CODE (expression) == FUNCTION_DECL
          && !(DECL_CLASS_SCOPE_P (expression)
               && dependent_type_p (DECL_CONTEXT (expression)))

    whereupon we ICE.

    This patch fixes it by deferring the class deduction until the
    enclosing scope is non-dependent.  build_deduction_guide and
maybe_aggr_guide
    needed a little tweaking to make the deduction work in a member
    template.

    Co-Authored-By: Jason Merrill <jason@redhat.com>

    gcc/cp/ChangeLog:

            PR c++/97034
            PR c++/99009
            * pt.c (build_deduction_guide): Use INNERMOST_TEMPLATE_ARGS.
            (maybe_aggr_guide): Use the original template type where needed. 
In
            a class member template, partially instantiate the result of
            collect_ctor_idx_types.
            (do_class_deduction): Defer the deduction until the enclosing
            scope is non-dependent.

    gcc/testsuite/ChangeLog:

            PR c++/97034
            PR c++/99009
            * g++.dg/cpp1z/class-deduction81.C: New test.
            * g++.dg/cpp1z/class-deduction82.C: New test.
            * g++.dg/cpp2a/class-deduction-aggr8.C: New test.
            * g++.dg/cpp2a/class-deduction-aggr9.C: New test.
            * g++.dg/cpp2a/class-deduction-aggr10.C: New test.

  parent reply	other threads:[~2021-03-03 14:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-12 14:51 [Bug c++/97034] New: " dimitri.gorokhovik at free dot fr
2020-09-13 22:16 ` [Bug c++/97034] [11 Regression] " mpolacek at gcc dot gnu.org
2020-09-16 16:27 ` mpolacek at gcc dot gnu.org
2020-09-16 18:02 ` mpolacek at gcc dot gnu.org
2020-09-16 18:42 ` mpolacek at gcc dot gnu.org
2020-10-12 11:52 ` rguenth at gcc dot gnu.org
2021-01-09  4:42 ` arthur.j.odwyer at gmail dot com
2021-02-12  1:27 ` mpolacek at gcc dot gnu.org
2021-02-12  1:44 ` mpolacek at gcc dot gnu.org
2021-02-12  4:15 ` mpolacek at gcc dot gnu.org
2021-03-03 14:53 ` cvs-commit at gcc dot gnu.org [this message]
2021-03-03 15:04 ` 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-97034-4-anryphMGOm@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).