From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 40D6F395B81B; Wed, 3 Mar 2021 14:53:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40D6F395B81B From: "cvs-commit at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2021 14:53:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97034 --- Comment #9 from CVS Commits --- The master branch has been updated by Marek Polacek : https://gcc.gnu.org/g:1dabbfb0f4a9fbdc77e1ea4db7302586f00895e1 commit r11-7483-g1dabbfb0f4a9fbdc77e1ea4db7302586f00895e1 Author: Marek Polacek 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 G(T)-> E::G we deduce T and create a partial instantiation: G(T) -> E::G [with T =3D 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 (), 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 c= an't be type-dependent. Checking this is important for functions with auto return type, which looks like a dependent type. */ if (TREE_CODE (expression) =3D=3D 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 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= .=20 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.=