re PR c++/52014 ([c++0x] Segfault When `decltype` Used in Nested Lambda Function...
authorJason Merrill <jason@redhat.com>
Mon, 25 Mar 2013 20:35:43 +0000 (16:35 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 25 Mar 2013 20:35:43 +0000 (16:35 -0400)
PR c++/52014
* semantics.c (lambda_expr_this_capture): Don't capture 'this' in
unevaluated context.

From-SVN: r197063

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C [new file with mode: 0644]

index 1209a8b6261121c388ce6f8bb289818ed3580adc..bac484498300ab3a99b36da7038ba9ce344e132c 100644 (file)
@@ -1,3 +1,9 @@
+2013-03-23  Jason Merrill  <jason@redhat.com>
+
+       PR c++/52014
+       * semantics.c (lambda_expr_this_capture): Don't capture 'this' in
+       unevaluated context.
+
 2013-03-25  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/56722
index e3aeb817a5208880cbfe0ee724b6ed6ad2030c0c..fb38e8d70118110dd21db402212c61cf92915af6 100644 (file)
@@ -9454,6 +9454,11 @@ lambda_expr_this_capture (tree lambda)
 
   tree this_capture = LAMBDA_EXPR_THIS_CAPTURE (lambda);
 
+  /* In unevaluated context this isn't an odr-use, so just return the
+     nearest 'this'.  */
+  if (cp_unevaluated_operand)
+    return lookup_name (this_identifier);
+
   /* Try to default capture 'this' if we can.  */
   if (!this_capture
       && LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) != CPLD_NONE)
@@ -9523,11 +9528,6 @@ lambda_expr_this_capture (tree lambda)
 
   if (!this_capture)
     {
-      /* In unevaluated context this isn't an odr-use, so just return the
-        nearest 'this'.  */
-      if (cp_unevaluated_operand)
-       return lookup_name (this_identifier);
-
       error ("%<this%> was not captured for this lambda function");
       result = error_mark_node;
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this14.C
new file mode 100644 (file)
index 0000000..9834bfd
--- /dev/null
@@ -0,0 +1,49 @@
+// PR c++/52014
+// { dg-require-effective-target c++11 }
+
+template <class Iterator, class Func>
+void for_each(const Iterator first, const Iterator last, Func func)
+{
+  for (Iterator it = first; it != last; ++it) {
+    func(*it);
+  }
+}
+
+template <class T>
+struct helper
+{
+  typedef typename T::size_type type;
+};
+
+template <class T>
+struct helper<T&>
+{
+  typedef typename T::size_type type;
+};
+
+template <class T>
+struct helper<T*>
+{
+  typedef typename T::size_type type;
+};
+
+struct bar
+{
+  struct foo
+  {
+    typedef int size_type;
+  } foo_;
+
+  void test()
+  {
+    int arr[] = { 1, 2, 3 };
+    for_each(arr, arr + 3, [&](helper<foo>::type i) {
+       for_each(arr, arr + 3, [&](helper<decltype(foo_)>::type j) { });
+      });
+  }
+};
+
+int main()
+{
+  return 0;
+}