public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/60252 (ICE with VLA in lambda parameter)
@ 2014-02-21 14:10 Jason Merrill
  2014-02-21 21:50 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2014-02-21 14:10 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 347 bytes --]

While parsing the template parameter list for a lambda, we've already 
pushed into the closure class but haven't created the op() 
FUNCTION_DECL, so trying to capture 'this' by way of the 'this' pointer 
of op() breaks.  Avoid the ICE by not trying to capture 'this' when 
parsing a parameter list.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 60252.patch --]
[-- Type: text/x-patch, Size: 1401 bytes --]

commit 415022d49d1cee84b6d2085e7585e1d801d15732
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 21 00:35:35 2014 -0500

    	PR c++/60252
    	* lambda.c (maybe_resolve_dummy): Don't try to capture this
    	in declaration context.

diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index ad993e9d..7fe235b 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -749,7 +749,10 @@ maybe_resolve_dummy (tree object)
   if (type != current_class_type
       && current_class_type
       && LAMBDA_TYPE_P (current_class_type)
-      && DERIVED_FROM_P (type, current_nonlambda_class_type ()))
+      && DERIVED_FROM_P (type, current_nonlambda_class_type ())
+      /* If we get here while parsing the parameter list of a lambda, it
+	 will fail, so don't even try (c++/60252).  */
+      && current_binding_level->kind != sk_function_parms)
     {
       /* In a lambda, need to go through 'this' capture.  */
       tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice11.C
new file mode 100644
index 0000000..58f0fa3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice11.C
@@ -0,0 +1,12 @@
+// PR c++/60252
+// { dg-require-effective-target c++11 }
+
+struct A
+{
+  int i;			// { dg-message "" }
+
+  void foo()
+  {
+    [&](){ [&](int[i]){}; };	// { dg-error "" }
+  }
+};

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C++ PATCH for c++/60252 (ICE with VLA in lambda parameter)
  2014-02-21 14:10 C++ PATCH for c++/60252 (ICE with VLA in lambda parameter) Jason Merrill
@ 2014-02-21 21:50 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2014-02-21 21:50 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 601 bytes --]

On 02/21/2014 09:10 AM, Jason Merrill wrote:
> While parsing the template parameter list for a lambda, we've already
> pushed into the closure class but haven't created the op()
> FUNCTION_DECL, so trying to capture 'this' by way of the 'this' pointer
> of op() breaks.  Avoid the ICE by not trying to capture 'this' when
> parsing a parameter list.

On second thought, I'd rather not depend on the parsing state here, 
since we don't always update current_binding_level during template 
instantiation.  So let's check for the actual problem instead.

Tested x86_64-pc-linux-gnu, applying to trunk.



[-- Attachment #2: 60252-2.patch --]
[-- Type: text/x-patch, Size: 1025 bytes --]

commit 5ca06118071f28b060b751415d18f8af4968a0a4
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 21 15:06:47 2014 -0500

    	PR c++/60252
    	* lambda.c (maybe_resolve_dummy): Check lambda_function rather
    	than current_binding_level.

diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 7fe235b..277dec6 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -749,10 +749,8 @@ maybe_resolve_dummy (tree object)
   if (type != current_class_type
       && current_class_type
       && LAMBDA_TYPE_P (current_class_type)
-      && DERIVED_FROM_P (type, current_nonlambda_class_type ())
-      /* If we get here while parsing the parameter list of a lambda, it
-	 will fail, so don't even try (c++/60252).  */
-      && current_binding_level->kind != sk_function_parms)
+      && lambda_function (current_class_type)
+      && DERIVED_FROM_P (type, current_nonlambda_class_type ()))
     {
       /* In a lambda, need to go through 'this' capture.  */
       tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-21 21:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-21 14:10 C++ PATCH for c++/60252 (ICE with VLA in lambda parameter) Jason Merrill
2014-02-21 21:50 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).