Bug 93867 - ICE using class type NTTPs and class template argument deduction
Summary: ICE using class type NTTPs and class template argument deduction
Status: RESOLVED DUPLICATE of bug 93295
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-02-21 10:29 UTC by Paul Keir
Modified: 2021-05-20 21:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
The code described in the bug report. (267 bytes, text/plain)
2020-02-21 10:29 UTC, Paul Keir
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Keir 2020-02-21 10:29:22 UTC
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
Comment 1 Marek Polacek 2020-02-21 13:35:36 UTC
Dup, I think.  Thanks for the nice testcase.

*** This bug has been marked as a duplicate of bug 93295 ***
Comment 2 GCC Commits 2021-04-10 04:07:11 UTC
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.
Comment 3 GCC Commits 2021-05-20 21:35:43 UTC
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.