commit a668cad5042d5e499b4d3c78e40505d22f061e3a
Author: Jason Merrill <jason@redhat.com>
Date: Wed Mar 27 16:04:00 2013 -0400
PR c++/56701
* semantics.c (finish_this_expr): 'this' is an rvalue.
* typeck.c (cp_build_indirect_ref): Handle NOP_EXPR of 'this'.
@@ -2297,7 +2297,6 @@ finish_this_expr (void)
result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type));
else
result = current_class_ptr;
-
}
else if (current_function_decl
&& DECL_STATIC_FUNCTION_P (current_function_decl))
@@ -2314,6 +2313,9 @@ finish_this_expr (void)
result = error_mark_node;
}
+ /* The keyword 'this' is a prvalue expression. */
+ result = rvalue (result);
+
return result;
}
@@ -2843,7 +2843,11 @@ cp_build_indirect_ref (tree ptr, ref_operator errorstring,
{
tree pointer, type;
- if (ptr == current_class_ptr)
+ if (ptr == current_class_ptr
+ || (TREE_CODE (ptr) == NOP_EXPR
+ && TREE_OPERAND (ptr, 0) == current_class_ptr
+ && (same_type_ignoring_top_level_qualifiers_p
+ (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr)))))
return current_class_ref;
pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE
new file mode 100644
@@ -0,0 +1,7 @@
+// PR c++/56701
+// { dg-require-effective-target c++11 }
+
+struct A
+{
+ void f(){ A*&& a = this; }
+};