Created attachment 47881 [details] The code described in the bug report. The attached C++20 code makes use of class type NTTPs, and also class template argument deduction. It is based on code from P0732r2. With the -std=c++2a switch the code produces an ICE on GCC snapshot gcc-10-20200216. The error message is below: nttp_ice.cpp: In function ‘int main(int, const char**)’: nttp_ice.cpp:27:16: internal compiler error: in alias_ctad_tweaks, at cp/pt.c:28327 27 | foo<"hello">(); | ^ 0x67b060 alias_ctad_tweaks ../../gcc/cp/pt.c:28327 0x67b060 deduction_guides_for ../../gcc/cp/pt.c:28499 0x9fc488 do_class_deduction ../../gcc/cp/pt.c:28604 0x9fc488 do_auto_deduction(tree_node*, tree_node*, tree_node*, int, auto_deduction_context, tree_node*, int) ../../gcc/cp/pt.c:28733 0x9fe129 convert_template_argument ../../gcc/cp/pt.c:8306 0x9fff7b coerce_template_parms ../../gcc/cp/pt.c:8810 0xa32fac fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool, bool) ../../gcc/cp/pt.c:20919 0x8951ed add_template_candidate_real ../../gcc/cp/call.c:3396 0x895c04 add_template_candidate ../../gcc/cp/call.c:3481 0x895c04 add_candidates ../../gcc/cp/call.c:5830 0x8960c7 add_candidates ../../gcc/cp/call.c:4478 0x8960c7 perform_overload_resolution ../../gcc/cp/call.c:4486 0x89bdb5 build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../gcc/cp/call.c:4560 0xa4ec54 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) ../../gcc/cp/semantics.c:2671 0x9c848d cp_parser_postfix_expression ../../gcc/cp/parser.c:7427 0x9ab24a cp_parser_binary_expression ../../gcc/cp/parser.c:9519 0x9acd0c cp_parser_assignment_expression ../../gcc/cp/parser.c:9824 0x9ad032 cp_parser_expression ../../gcc/cp/parser.c:9992 0x9aff26 cp_parser_expression_statement ../../gcc/cp/parser.c:11642 0x9bb083 cp_parser_statement ../../gcc/cp/parser.c:11438
Dup, I think. Thanks for the nice testcase. *** This bug has been marked as a duplicate of bug 93295 ***
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:1a19d334ce493ec2ce2daeac74beef63fd67e2bc commit r11-8104-g1a19d334ce493ec2ce2daeac74beef63fd67e2bc Author: Jason Merrill <jason@redhat.com> Date: Fri Apr 9 18:02:38 2021 -0400 c++: deduction guide using alias [PR99180] alias_ctad_tweaks was expecting that all deduction guides for the class would be suitable for deduction from the alias definition; in this case, the deduction guide uses 'true' and the alias B uses 'false', so deduction fails. But that's OK, we just don't use that deduction guide. I also noticed that we were giving up on deduction entirely if substitution failed for some guide; we should only give up on that particular deduction guide. We ought to give a better diagnostic about this case when deduction fails, but that can wait. gcc/cp/ChangeLog: PR c++/99180 PR c++/93295 PR c++/93867 PR c++/99118 PR c++/96873 * pt.c (alias_ctad_tweaks): Handle failure better. gcc/testsuite/ChangeLog: PR c++/99180 PR c++/93295 PR c++/93867 PR c++/95486 * g++.dg/cpp2a/class-deduction-alias5.C: New test. * g++.dg/cpp2a/class-deduction-alias6.C: New test. * g++.dg/cpp2a/class-deduction-alias7.C: New test. * g++.dg/cpp2a/class-deduction-alias8.C: New test.
The releases/gcc-10 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:92e9b2a995f718f1c2ab1cd0840b439c24d3535f commit r10-9852-g92e9b2a995f718f1c2ab1cd0840b439c24d3535f Author: Jason Merrill <jason@redhat.com> Date: Fri Apr 9 18:02:38 2021 -0400 c++: deduction guide using alias [PR99180] alias_ctad_tweaks was expecting that all deduction guides for the class would be suitable for deduction from the alias definition; in this case, the deduction guide uses 'true' and the alias B uses 'false', so deduction fails. But that's OK, we just don't use that deduction guide. I also noticed that we were giving up on deduction entirely if substitution failed for some guide; we should only give up on that particular deduction guide. We ought to give a better diagnostic about this case when deduction fails, but that can wait. gcc/cp/ChangeLog: PR c++/99180 PR c++/93295 PR c++/93867 PR c++/99118 PR c++/96873 * pt.c (alias_ctad_tweaks): Handle failure better. gcc/testsuite/ChangeLog: PR c++/99180 PR c++/93295 PR c++/93867 PR c++/95486 * g++.dg/cpp2a/class-deduction-alias5.C: New test. * g++.dg/cpp2a/class-deduction-alias6.C: New test. * g++.dg/cpp2a/class-deduction-alias7.C: New test. * g++.dg/cpp2a/class-deduction-alias8.C: New test.