[gcc r9-8319] PR c++/90732 - ICE with VLA capture and generic lambda.
Jason Merrill
jason@gcc.gnu.org
Mon Mar 2 21:25:00 GMT 2020
https://gcc.gnu.org/g:1ccbda907d1fd3a202ff2bd951828cc97abb1a8d
commit r9-8319-g1ccbda907d1fd3a202ff2bd951828cc97abb1a8d
Author: Jason Merrill <jason@redhat.com>
Date: Mon Mar 2 14:42:47 2020 -0500
PR c++/90732 - ICE with VLA capture and generic lambda.
We were failing to handle VLA capture in tsubst_lambda_expr; initially
building a DECLTYPE_TYPE for the capture and then tsubsting it doesn't give
the special VLA handling. So with this patch we call add_capture again for
VLAs.
gcc/cp/ChangeLog
2020-03-02 Jason Merrill <jason@redhat.com>
PR c++/90732 - ICE with VLA capture and generic lambda.
* pt.c (tsubst_lambda_expr): Repeat add_capture for VLAs.
Diff:
---
gcc/cp/ChangeLog | 5 +++++
gcc/cp/pt.c | 37 ++++++++++++++++++++++++++------
gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C | 16 ++++++++++++++
3 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 80971a9..2b134ee 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2020-03-02 Jason Merrill <jason@redhat.com>
+ PR c++/90732 - ICE with VLA capture and generic lambda.
+ * pt.c (tsubst_lambda_expr): Repeat add_capture for VLAs.
+
+2020-03-02 Jason Merrill <jason@redhat.com>
+
PR c++/90333
PR c++/89640
PR c++/60503
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c7ca7e4..f233e78 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18130,6 +18130,36 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
cap = TREE_CHAIN (cap))
{
tree ofield = TREE_PURPOSE (cap);
+ tree init = TREE_VALUE (cap);
+ if (PACK_EXPANSION_P (init))
+ init = tsubst_pack_expansion (init, args, complain, in_decl);
+ else
+ init = tsubst_copy_and_build (init, args, complain, in_decl,
+ /*fn*/false, /*constexpr*/false);
+
+ if (init == error_mark_node)
+ return error_mark_node;
+
+ if (init && TREE_CODE (init) == TREE_LIST)
+ init = build_x_compound_expr_from_list (init, ELK_INIT, complain);
+
+ if (!processing_template_decl
+ && init && TREE_CODE (init) != TREE_VEC
+ && variably_modified_type_p (TREE_TYPE (init), NULL_TREE))
+ {
+ /* For a VLA, simply tsubsting the field type won't work, we need to
+ go through add_capture again. XXX do we want to do this for all
+ captures? */
+ tree name = (get_identifier
+ (IDENTIFIER_POINTER (DECL_NAME (ofield)) + 2));
+ tree ftype = TREE_TYPE (ofield);
+ bool by_ref = (TYPE_REF_P (ftype)
+ || (TREE_CODE (ftype) == DECLTYPE_TYPE
+ && DECLTYPE_FOR_REF_CAPTURE (ftype)));
+ add_capture (r, name, init, by_ref, !DECL_NORMAL_CAPTURE_P (ofield));
+ continue;
+ }
+
if (PACK_EXPANSION_P (ofield))
ofield = PACK_EXPANSION_PATTERN (ofield);
tree field = tsubst_decl (ofield, args, complain);
@@ -18144,13 +18174,6 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (field == error_mark_node)
return error_mark_node;
- tree init = TREE_VALUE (cap);
- if (PACK_EXPANSION_P (init))
- init = tsubst_pack_expansion (init, args, complain, in_decl);
- else
- init = tsubst_copy_and_build (init, args, complain, in_decl,
- /*fn*/false, /*constexpr*/false);
-
if (TREE_CODE (field) == TREE_VEC)
{
int len = TREE_VEC_LENGTH (field);
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C
new file mode 100644
index 0000000..c9025c7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C
@@ -0,0 +1,16 @@
+// PR c++/90732
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-Wno-vla" }
+
+/*const*/ int SIZE = 100;
+
+template<typename T>
+int foo(T t) {
+ char buf[SIZE] = { 24 };
+ return [&buf](auto x){ return buf[x]; }(t);
+}
+
+int main() {
+ if (foo(0) != 24)
+ __builtin_abort();
+}
More information about the Gcc-cvs
mailing list