Bug 77522 - [7 Regression] ICE on invalid code C++14 code: in tsubst_decl, at cp/pt.c:12447
Summary: [7 Regression] ICE on invalid code C++14 code: in tsubst_decl, at cp/pt.c:12447
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P4 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2016-09-08 03:13 UTC by Zhendong Su
Modified: 2019-11-14 09:29 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.0
Known to fail: 7.5.0
Last reconfirmed: 2016-09-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2016-09-08 03:13:44 UTC
It affects 4.9.x and later, which have C++14 support. 


$ g++-trunk -c -std=c++14 small.cpp
small.cpp: In instantiation of ‘f(T)::<lambda()> [with T = int]’:
small.cpp:3:18:   required from ‘struct f(T) [with T = int]::<lambda()>’
small.cpp:3:8:   required from ‘void f(T) [with T = int]’
small.cpp:8:7:   required from here
small.cpp:3:24: error: use of ‘f(T) [with T = int]::<lambda()>::__a’ before deduction of ‘auto’
   auto g = [&a = f] () {};
                        ^
small.cpp:3:24: error: use of ‘f(T) [with T = int]::<lambda()>::__a’ before deduction of ‘auto’
small.cpp:3:24: internal compiler error: in tsubst_decl, at cp/pt.c:12447
0x6fe7c6 tsubst_decl
        ../../gcc-source-trunk/gcc/cp/pt.c:12447
0x6f32de tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-source-trunk/gcc/cp/pt.c:12907
0x6e07fa tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15284
0x6dfa43 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15419
0x6dd120 instantiate_decl(tree_node*, int, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:22159
0x7266b5 instantiate_class_template_1
        ../../gcc-source-trunk/gcc/cp/pt.c:10346
0x7266b5 instantiate_class_template(tree_node*)
        ../../gcc-source-trunk/gcc/cp/pt.c:10416
0x7cbf13 complete_type(tree_node*)
        ../../gcc-source-trunk/gcc/cp/typeck.c:133
0x6eaf2c tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:17269
0x6df247 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15936
0x5df520 tsubst_init
        ../../gcc-source-trunk/gcc/cp/pt.c:13966
0x6e3144 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15334
0x6dec3b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15228
0x6dfa43 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15419
0x6dd120 instantiate_decl(tree_node*, int, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:22159
0x72a5f2 instantiate_pending_templates(int)
        ../../gcc-source-trunk/gcc/cp/pt.c:22278
0x76f597 c_parse_final_cleanups()
        ../../gcc-source-trunk/gcc/cp/decl2.c:4617
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$


-----------------------------------------


template < class T = int > void f (T)
{ 
  auto g = [&a = f] () {};
}

int main ()
{ 
  f (0);
  return 0;
}
Comment 1 Martin Liška 2016-09-10 10:38:12 UTC
Confirmed.
Comment 2 Jakub Jelinek 2016-09-15 14:37:20 UTC
Started with r210017.  Before that it has been rejected:
pr77522.C: In function ‘void f(T)’:
pr77522.C:3:18: error: cannot capture ‘f’ by reference
   auto g = [&a = f] () {};
                  ^
pr77522.C: In instantiation of ‘struct f(T) [with T = int]::<lambda>’:
pr77522.C:3:25:   required from ‘void f(T) [with T = int]’
pr77522.C:8:7:   required from here
pr77522.C:3:18: error: unable to deduce ‘auto’ from ‘f’
pr77522.C:3:18: error: using invalid field ‘f(T)::<lambda()>::a’
Comment 3 Paolo Carlini 2018-02-08 22:57:04 UTC
In trunk we don't ICE anymore on this, I think we can safely remove the 8 Regression marker and commit a testcase. I'm wondering however why when initialize_reference calls error_at the input_location is at the open square bracket. Well, just a curiosity, at some point expr itself will have its own usable location.
Comment 4 Jakub Jelinek 2018-02-09 10:48:18 UTC
The ICE got fixed with r251433.  Since then the error is:
pr77522.C: In instantiation of ‘void f(T) [with T = int]’:
pr77522.C:8:7:   required from here
pr77522.C:3:8: error: use of ‘f(T) [with T = int]::<lambda()>::__a’ before deduction of ‘auto’
   auto g = [&a = f] () {};
        ^
pr77522.C:3:12: error: invalid initialization of non-const reference of type ‘auto&’ from an rvalue of type ‘<unresolved overloaded function type>’
   auto g = [&a = f] () {};
            ^

Paolo, will you check the testcase in and remove 8 Regression?
Comment 5 paolo@gcc.gnu.org 2018-02-09 11:37:46 UTC
Author: paolo
Date: Fri Feb  9 11:37:14 2018
New Revision: 257521

URL: https://gcc.gnu.org/viewcvs?rev=257521&root=gcc&view=rev
Log:
2018-02-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/77522
	* g++.dg/cpp1y/lambda-init16.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-init16.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 6 Paolo Carlini 2018-02-09 11:38:31 UTC
Done.
Comment 7 Jakub Jelinek 2018-10-26 10:23:34 UTC
GCC 6 branch is being closed
Comment 8 Richard Biener 2019-11-14 09:29:11 UTC
Fixed in GCC8.