[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 Marek Polacek changed: What|Removed |Added Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #10 from Marek Polacek --- Fixed.
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- 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 = 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 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 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.
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- Comment #8 from Marek Polacek --- Alternative patch that I'm more happy about: --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -28761,6 +28761,7 @@ build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t com tree ded_fn = build_lang_decl_loc (loc, FUNCTION_DECL, dguide_name (type), fntype); + DECL_CONTEXT (ded_fn) = type; DECL_ARGUMENTS (ded_fn) = fargs; DECL_ARTIFICIAL (ded_fn) = true; DECL_NONCONVERTING_P (ded_fn) = explicit_p;
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- Comment #7 from Marek Polacek --- Candidate patch: --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -27279,7 +27279,10 @@ type_dependent_expression_p (tree expression) && DECL_UNIQUE_FRIEND_P (expression) && (!DECL_FRIEND_CONTEXT (expression) || dependent_type_p (DECL_FRIEND_CONTEXT (expression - && !DECL_LOCAL_DECL_P (expression)) + && !DECL_LOCAL_DECL_P (expression) + /* We build deduction guides without any DECL_CONTEXT, but they can +be type-dependent. */ + && !deduction_guide_p (expression)) { gcc_assert (!dependent_type_p (TREE_TYPE (expression)) || undeduced_auto_decl (expression));
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- Comment #6 from Marek Polacek --- (In reply to Arthur O'Dwyer from comment #5) > Is mine the same bug? Mine is also a regression (trunk crashes where GCC > 10.2 had succeeded). > > // https://godbolt.org/z/Ysh6as > struct C { void f(auto) noexcept; }; > void C::f(auto) noexcept(C::x) {} > > Compile with -std=c++20: > > > :3:29: error: 'x' is not a member of 'C' > 3 | void C::f(auto) noexcept(C::x) {} > | ^ > :3:6: error: declaration of 'void C::f(auto:2)' has a different > exception specifier > 3 | void C::f(auto) noexcept(C::x) {} > | ^ > :2:17: note: from previous declaration 'void C::f(auto:1) noexcept' > 2 | struct C { void f(auto) noexcept; }; > | ^ > :3:30: internal compiler error: in type_dependent_expression_p, at > cp/pt.c:27166 > 3 | void C::f(auto) noexcept(C::x) {} > | ^ > 0x1cc31d9 internal_error(char const*, ...) > ???:0 > 0x6b25f7 fancy_abort(char const*, int, char const*) > ???:0 > 0x8ee70a type_dependent_expression_p(tree_node*) > ???:0 > 0x137d4f3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), > void*, hash_set >*, > tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), > void*, hash_set >*)) > ???:0 > 0x1381b55 walk_tree_without_duplicates_1(tree_node**, tree_node* > (*)(tree_node**, int*, void*), void*, tree_node* (*)(tree_node**, int*, > tree_node* (*)(tree_node**, int*, void*), void*, hash_set default_hash_traits >*)) > ???:0 > 0x8ea937 instantiation_dependent_uneval_expression_p(tree_node*) > ???:0 > 0x8f2198 instantiation_dependent_expression_p(tree_node*) > ???:0 > 0x8f2216 uses_template_parms(tree_node*) > ???:0 > 0x78ffe8 duplicate_decls(tree_node*, tree_node*, bool, bool) > ???:0 > 0x79a2b6 grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, > decl_context, int, tree_node**) > ???:0 > 0x79dda6 start_function(cp_decl_specifier_seq*, cp_declarator const*, > tree_node*) > ???:0 > 0x8d803d c_parse_file() > ???:0 > 0xa54072 c_common_parse_file() > ???:0 I think that is a different problem (the original problem here was with deduction guides).
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 Arthur O'Dwyer changed: What|Removed |Added CC||arthur.j.odwyer at gmail dot com --- Comment #5 from Arthur O'Dwyer --- Is mine the same bug? Mine is also a regression (trunk crashes where GCC 10.2 had succeeded). // https://godbolt.org/z/Ysh6as struct C { void f(auto) noexcept; }; void C::f(auto) noexcept(C::x) {} Compile with -std=c++20: :3:29: error: 'x' is not a member of 'C' 3 | void C::f(auto) noexcept(C::x) {} | ^ :3:6: error: declaration of 'void C::f(auto:2)' has a different exception specifier 3 | void C::f(auto) noexcept(C::x) {} | ^ :2:17: note: from previous declaration 'void C::f(auto:1) noexcept' 2 | struct C { void f(auto) noexcept; }; | ^ :3:30: internal compiler error: in type_dependent_expression_p, at cp/pt.c:27166 3 | void C::f(auto) noexcept(C::x) {} | ^ 0x1cc31d9 internal_error(char const*, ...) ???:0 0x6b25f7 fancy_abort(char const*, int, char const*) ???:0 0x8ee70a type_dependent_expression_p(tree_node*) ???:0 0x137d4f3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set >*)) ???:0 0x1381b55 walk_tree_without_duplicates_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set >*)) ???:0 0x8ea937 instantiation_dependent_uneval_expression_p(tree_node*) ???:0 0x8f2198 instantiation_dependent_expression_p(tree_node*) ???:0 0x8f2216 uses_template_parms(tree_node*) ???:0 0x78ffe8 duplicate_decls(tree_node*, tree_node*, bool, bool) ???:0 0x79a2b6 grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**) ???:0 0x79dda6 start_function(cp_decl_specifier_seq*, cp_declarator const*, tree_node*) ???:0 0x8d803d c_parse_file() ???:0 0xa54072 c_common_parse_file() ???:0
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 Richard Biener changed: What|Removed |Added Priority|P3 |P1
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- Comment #4 from Marek Polacek --- Another, valid, where C++20 aggregate CTAD should work: template struct E { template struct G { T t; }; void fn() { G{1}; } }; void g () { E e; e.fn (); }
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- Comment #3 from Marek Polacek --- The same ICE can be triggered with template struct E { template struct G { T t; G(T) { } }; void fn() { G{1}; } }; which started with r269093.
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 --- Comment #2 from Marek Polacek --- // PR c++/97034 namespace N { template struct S { template S(T, U); }; } // namespace N template struct E { template struct G { T t; }; void fn() { G{N::S{'a', 1}}; } };
[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*))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97034 Marek Polacek changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Ever confirmed|0 |1 Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org Keywords||ice-on-valid-code Summary|ICE on C++20 code: |[11 Regression] ICE on |gcc_assert failure in |C++20 code: gcc_assert |return type deduction |failure in return type |(gcc/cp/pt.c:26984 in |deduction |type_dependent_expression_p |(gcc/cp/pt.c:26984 in |(tree_node*)) |type_dependent_expression_p ||(tree_node*)) Last reconfirmed||2020-09-13 Target Milestone|--- |11.0 CC||mpolacek at gcc dot gnu.org --- Comment #1 from Marek Polacek --- Started with r11-1713.