OSDN Git Service

PR c++/43856
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Apr 2010 21:26:25 +0000 (21:26 +0000)
committerMasaki Muranaka <monaka@monami-software.com>
Sun, 23 May 2010 04:52:59 +0000 (13:52 +0900)
* name-lookup.c (qualify_lookup): Disqualify lambda op().
* class.c (current_nonlambda_class_type): New fn.
* semantics.c (nonlambda_method_basetype): New.
* cp-tree.h: Declare them.
* tree.c (maybe_dummy_object): Handle implicit 'this' capture.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158807 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/semantics.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this2.C

index d0a112c..4dd3df4 100644 (file)
@@ -1,5 +1,12 @@
 2010-04-27  Jason Merrill  <jason@redhat.com>
 
+       PR c++/43856
+       * name-lookup.c (qualify_lookup): Disqualify lambda op().
+       * class.c (current_nonlambda_class_type): New fn.
+       * semantics.c (nonlambda_method_basetype): New.
+       * cp-tree.h: Declare them.
+       * tree.c (maybe_dummy_object): Handle implicit 'this' capture.
+
        * semantics.c (baselink_for_fns): Correct BASELINK_BINFO.
 
        PR c++/43875
index dd89171..62e92cc 100644 (file)
@@ -4580,6 +4580,7 @@ extern void resort_type_method_vec                (void *, void *,
 extern bool add_method                         (tree, tree, tree);
 extern bool currently_open_class               (tree);
 extern tree currently_open_derived_class       (tree);
+extern tree current_nonlambda_class_type       (void);
 extern tree finish_struct                      (tree, tree);
 extern void finish_struct_1                    (tree);
 extern int resolves_to_fixed_type_p            (tree, int *);
@@ -5212,6 +5213,7 @@ extern tree add_capture                         (tree, tree, tree, bool, bool);
 extern tree add_default_capture                 (tree, tree, tree);
 extern void register_capture_members           (tree);
 extern tree lambda_expr_this_capture            (tree);
+extern tree nonlambda_method_basetype          (void);
 extern void maybe_add_lambda_conv_op            (tree);
 
 /* in tree.c */
index 6bf33c7..7c03959 100644 (file)
@@ -5869,6 +5869,32 @@ lambda_expr_this_capture (tree lambda)
   return result;
 }
 
+/* Returns the method basetype of the innermost non-lambda function, or
+   NULL_TREE if none.  */
+
+tree
+nonlambda_method_basetype (void)
+{
+  tree fn, type;
+  if (!current_class_ref)
+    return NULL_TREE;
+
+  type = current_class_type;
+  if (!LAMBDA_TYPE_P (type))
+    return type;
+
+  /* Find the nearest enclosing non-lambda function.  */
+  fn = TYPE_NAME (type);
+  do
+    fn = decl_function_context (fn);
+  while (fn && LAMBDA_FUNCTION_P (fn));
+
+  if (!fn || !DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
+    return NULL_TREE;
+
+  return TYPE_METHOD_BASETYPE (TREE_TYPE (fn));
+}
+
 /* If the closure TYPE has a static op(), also add a conversion to function
    pointer.  */
 
index 0abc12c..f8b2c40 100644 (file)
@@ -2293,11 +2293,11 @@ maybe_dummy_object (tree type, tree* binfop)
 {
   tree decl, context;
   tree binfo;
+  tree current = current_nonlambda_class_type ();
 
-  if (current_class_type
-      && (binfo = lookup_base (current_class_type, type,
-                              ba_unique | ba_quiet, NULL)))
-    context = current_class_type;
+  if (current
+      && (binfo = lookup_base (current, type, ba_any, NULL)))
+    context = current;
   else
     {
       /* Reference from a nested class member function.  */
@@ -2315,6 +2315,13 @@ maybe_dummy_object (tree type, tree* binfop)
       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
                      current_class_type))
     decl = current_class_ref;
+  else if (current != current_class_type
+          && context == nonlambda_method_basetype ())
+    /* In a lambda, need to go through 'this' capture.  */
+    decl = (cp_build_indirect_ref
+           ((lambda_expr_this_capture
+             (CLASSTYPE_LAMBDA_EXPR (current_class_type))),
+            RO_NULL, tf_warning_or_error));
   else
     decl = build_dummy_object (context);
 
index 0746e59..37f201a 100644 (file)
@@ -1,5 +1,8 @@
 2010-04-27  Jason Merrill  <jason@redhat.com>
 
+       PR c++/43856
+       * g++.dg/cpp0x/lambda/lambda-this2.C: New.
+
        PR c++/43875
        * g++.dg/cpp0x/lambda/lambda-deduce2.C: New.
 
index 04fe474..ce4bda4 100644 (file)
@@ -10,7 +10,6 @@ struct S1 {
     [=]() {
       i;
       g();
-      S1::g();
       operator()(42);
     };
   }