OSDN Git Service

PR c++/53599
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jun 2012 15:01:17 +0000 (15:01 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jun 2012 15:01:17 +0000 (15:01 +0000)
Revert:
PR c++/53137
* pt.c (instantiate_class_template_1): Set LAMBDA_EXPR_THIS_CAPTURE.
(instantiate_decl): Don't push_to_top_level for local class methods.
(instantiate_class_template_1): Or for local classes.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@188460 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template5.C [deleted file]
gcc/testsuite/g++.dg/template/local7.C [new file with mode: 0644]

index 44d2e1b..95f7604 100644 (file)
@@ -1,3 +1,12 @@
+2012-06-12  Jason Merrill  <jason@redhat.com>
+
+       PR c++/53599
+       Revert:
+       PR c++/53137
+       * pt.c (instantiate_class_template_1): Set LAMBDA_EXPR_THIS_CAPTURE.
+       (instantiate_decl): Don't push_to_top_level for local class methods.
+       (instantiate_class_template_1): Or for local classes.
+
 2012-06-04  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/53524
index a2d8374..e4631e7 100644 (file)
@@ -8734,7 +8734,6 @@ instantiate_class_template_1 (tree type)
   tree pbinfo;
   tree base_list;
   unsigned int saved_maximum_field_alignment;
-  tree fn_context;
 
   if (type == error_mark_node)
     return error_mark_node;
@@ -8793,9 +8792,7 @@ instantiate_class_template_1 (tree type)
      it now.  */
   push_deferring_access_checks (dk_no_deferred);
 
-  fn_context = decl_function_context (TYPE_MAIN_DECL (type));
-  if (!fn_context)
-    push_to_top_level ();
+  push_to_top_level ();
   /* Use #pragma pack from the template context.  */
   saved_maximum_field_alignment = maximum_field_alignment;
   maximum_field_alignment = TYPE_PRECISION (pattern);
@@ -9194,14 +9191,8 @@ instantiate_class_template_1 (tree type)
              apply_lambda_return_type (lambda, void_type_node);
              LAMBDA_EXPR_RETURN_TYPE (lambda) = NULL_TREE;
            }
-
-         LAMBDA_EXPR_THIS_CAPTURE (lambda)
-           = lookup_field_1 (type, get_identifier ("__this"), false);
-
          instantiate_decl (decl, false, false);
          maybe_add_lambda_conv_op (type);
-
-         LAMBDA_EXPR_THIS_CAPTURE (lambda) = NULL_TREE;
        }
       else
        gcc_assert (errorcount);
@@ -9232,8 +9223,7 @@ instantiate_class_template_1 (tree type)
   perform_deferred_access_checks ();
   pop_nested_class ();
   maximum_field_alignment = saved_maximum_field_alignment;
-  if (!fn_context)
-    pop_from_top_level ();
+  pop_from_top_level ();
   pop_deferring_access_checks ();
   pop_tinst_level ();
 
@@ -18466,10 +18456,9 @@ instantiate_decl (tree d, int defer_ok,
   tree spec;
   tree gen_tmpl;
   bool pattern_defined;
+  int need_push;
   location_t saved_loc = input_location;
   bool external_p;
-  tree fn_context;
-  bool nested;
 
   /* This function should only be used to instantiate templates for
      functions and static member variables.  */
@@ -18704,12 +18693,9 @@ instantiate_decl (tree d, int defer_ok,
        goto out;
     }
 
-  fn_context = decl_function_context (d);
-  nested = (current_function_decl != NULL_TREE);
-  if (!fn_context)
+  need_push = !cfun || !global_bindings_p ();
+  if (need_push)
     push_to_top_level ();
-  else if (nested)
-    push_function_context ();
 
   /* Mark D as instantiated so that recursive calls to
      instantiate_decl do not try to instantiate it again.  */
@@ -18822,10 +18808,8 @@ instantiate_decl (tree d, int defer_ok,
   /* We're not deferring instantiation any more.  */
   TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (d)) = 0;
 
-  if (!fn_context)
+  if (need_push)
     pop_from_top_level ();
-  else if (nested)
-    pop_function_context ();
 
 out:
   input_location = saved_loc;
index b7c373f..c8168b0 100644 (file)
@@ -1,3 +1,12 @@
+2012-06-12  Jason Merrill  <jason@redhat.com>
+
+       PR c++/53599
+       * g++.dg/template/local7.C: New.
+
+       Revert:
+       PR c++/53137
+       * g++.dg/cpp0x/lambda/lambda-template5.C: New.
+
 2012-06-04  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/53524
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template5.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template5.C
deleted file mode 100644 (file)
index b91b89f..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// PR c++/53137
-// { dg-do compile { target c++11 } }
-
-struct A
-{
-  template <typename T> void f();
-
-  template <typename T> void g()
-  {
-    [this]{ f<T>(); }();
-  }
-
-  void h()
-  {
-    g<int>();
-  }
-};
diff --git a/gcc/testsuite/g++.dg/template/local7.C b/gcc/testsuite/g++.dg/template/local7.C
new file mode 100644 (file)
index 0000000..3045534
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/53599
+
+template <typename T>
+int foo ()
+{
+  struct F;
+  struct G
+  {
+    static int F::* bar();
+  };
+
+  return sizeof(G);
+}
+
+int z = foo <int> ();