Bug 58597 - [5 Regression] ICE with lambda in default argument of template function
Summary: [5 Regression] ICE with lambda in default argument of template function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.3
Assignee: Jason Merrill
URL:
Keywords: c++-lambda, ice-on-valid-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2013-10-02 20:24 UTC by Volker Reichelt
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.9.2
Known to fail: 4.5.0, 4.6.0, 4.7.0, 4.8.0, 4.9.0
Last reconfirmed: 2013-10-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2013-10-02 20:24:56 UTC
The following valid code snippet (compiled with "-std=c++11") triggers an ICE since GCC 4.5.0 (when lambdas were introduced):

===============================================================
template<typename> struct A
{
  template<typename T> A(T, int = []{ return 0; }()) {}
};

A<int> a = 0;
===============================================================

bug.cc: In substitution of 'template<class T> A< <template-parameter-1-1> >::A(T, int) [with T = int]':
bug.cc:6:12:   required from here
bug.cc:6:12: internal compiler error: in instantiate_template_1, at cp/pt.c:15008
 A<int> a = 0;
            ^
0x5d0b93 instantiate_template_1
        ../../gcc/gcc/cp/pt.c:15008
0x5d0b93 instantiate_template(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/pt.c:15117
0x5d264a fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, bool, bool)
        ../../gcc/gcc/cp/pt.c:15466
0x53f0fc add_template_candidate_real
        ../../gcc/gcc/cp/call.c:2923
0x53ae69 add_template_candidate
        ../../gcc/gcc/cp/call.c:3020
0x53ae69 add_candidates
        ../../gcc/gcc/cp/call.c:5075
0x53bd40 build_user_type_conversion_1
        ../../gcc/gcc/cp/call.c:3484
0x546013 build_user_type_conversion(tree_node*, tree_node*, int, int)
        ../../gcc/gcc/cp/call.c:3653
0x6843da ocp_convert(tree_node*, tree_node*, int, int, int)
        ../../gcc/gcc/cp/cvt.c:865
0x6913dd expand_default_init
        ../../gcc/gcc/cp/init.c:1597
0x6913dd expand_aggr_init_1
        ../../gcc/gcc/cp/init.c:1766
0x693b79 build_aggr_init(tree_node*, tree_node*, int, int)
        ../../gcc/gcc/cp/init.c:1517
0x557da5 build_aggr_init_full_exprs
        ../../gcc/gcc/cp/decl.c:5543
0x557da5 check_initializer
        ../../gcc/gcc/cp/decl.c:5678
0x56aa5c cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        ../../gcc/gcc/cp/decl.c:6347
0x65196f cp_parser_init_declarator
        ../../gcc/gcc/cp/parser.c:16567
0x65207f cp_parser_simple_declaration
        ../../gcc/gcc/cp/parser.c:10986
0x653ee0 cp_parser_block_declaration
        ../../gcc/gcc/cp/parser.c:10867
0x65cf1e cp_parser_declaration
        ../../gcc/gcc/cp/parser.c:10764
0x65bc8a cp_parser_declaration_seq_opt
        ../../gcc/gcc/cp/parser.c:10650
Please submit a full bug report, [etc.]
Comment 1 Marek Polacek 2013-10-03 10:36:16 UTC
Started with r180707.
Comment 2 Paolo Carlini 2013-10-04 01:12:06 UTC
Now, Marek, since this is known to fail even with 4.5.0 (with -std=c++0x of course) there is definitely something wrong with your pointing to r180707.

I wonder if the fact that before r180707 one couldn't use -std=c++11, had to use -std=c++0x, is somehow fooling your scripts...
Comment 3 Marek Polacek 2013-10-04 08:08:18 UTC
Yeah, indeed :(.  As it's too old, I don't have enough cc1plus binaries to really bisect it.  Sorry.
Comment 4 Volker Reichelt 2015-01-14 08:01:48 UTC
The ICE disappered on the 4.9 branch in GCC 4.9.2.
But the testcase still crashes trunk with a different stack trace:


bug.cc:6:12: internal compiler error: Segmentation fault
 A<int> a = 0;
            ^
0xcdc42f crash_signal
        ../../gcc/gcc/toplev.c:372
0x6943ae tsubst_default_argument(tree_node*, tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/pt.c:10496
0x629f9f convert_default_arg(tree_node*, tree_node*, tree_node*, int, int)
        ../../gcc/gcc/cp/call.c:6774
0x62a91d build_over_call
        ../../gcc/gcc/cp/call.c:7301
0x62f9b4 convert_like_real
        ../../gcc/gcc/cp/call.c:6253
0x62f799 convert_like_real
        ../../gcc/gcc/cp/call.c:6384
0x6395d7 build_user_type_conversion(tree_node*, tree_node*, int, int)
        ../../gcc/gcc/cp/call.c:3831
0x78897e ocp_convert(tree_node*, tree_node*, int, int, int)
        ../../gcc/gcc/cp/cvt.c:875
0x7969f5 expand_default_init
        ../../gcc/gcc/cp/init.c:1661
0x7969f5 expand_aggr_init_1
        ../../gcc/gcc/cp/init.c:1830
0x7971e4 build_aggr_init(tree_node*, tree_node*, int, int)
        ../../gcc/gcc/cp/init.c:1582
0x66cddc build_aggr_init_full_exprs
        ../../gcc/gcc/cp/decl.c:5780
0x66cddc check_initializer
        ../../gcc/gcc/cp/decl.c:5924
0x66e79c cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        ../../gcc/gcc/cp/decl.c:6607
0x756539 cp_parser_init_declarator
        ../../gcc/gcc/cp/parser.c:17290
0x758185 cp_parser_simple_declaration
        ../../gcc/gcc/cp/parser.c:11600
0x7585b3 cp_parser_block_declaration
        ../../gcc/gcc/cp/parser.c:11474
0x760689 cp_parser_declaration
        ../../gcc/gcc/cp/parser.c:11371
0x76098a cp_parser_declaration_seq_opt
        ../../gcc/gcc/cp/parser.c:11257
0x760cc7 cp_parser_translation_unit
        ../../gcc/gcc/cp/parser.c:4108
Please submit a full bug report, [etc.]
Comment 5 Paolo Carlini 2015-01-16 16:52:03 UTC
Thus a regression.
Comment 6 Jason Merrill 2015-01-27 21:41:31 UTC
Author: jason
Date: Tue Jan 27 21:40:45 2015
New Revision: 220192

URL: https://gcc.gnu.org/viewcvs?rev=220192&root=gcc&view=rev
Log:
	PR c++/58597
	* lambda.c (maybe_add_lambda_conv_op): Check cfun rather than
	current_function_decl.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg6.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/lambda.c
Comment 7 Jason Merrill 2015-01-28 17:36:22 UTC
Fixed.