aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-03-28 14:20:51 -0400
committerJason Merrill <jason@gcc.gnu.org>2013-03-28 14:20:51 -0400
commit374b2837482811e9d5a2ec4b2db0dabd67e6d420 (patch)
treeb2c999ccf8f435806dfed3d500f9e9e5b866799b
parentfad882c6d9f520191ea301a023aa86e348049973 (diff)
downloadgcc-374b2837482811e9d5a2ec4b2db0dabd67e6d420.zip
gcc-374b2837482811e9d5a2ec4b2db0dabd67e6d420.tar.gz
gcc-374b2837482811e9d5a2ec4b2db0dabd67e6d420.tar.bz2
re PR c++/56701 ([C++11] The *this* pointer fails to bind to rvalue reference to pointer type)
PR c++/56701 * semantics.c (finish_this_expr): 'this' is an rvalue. * typeck.c (cp_build_indirect_ref): Handle NOP_EXPR of 'this'. From-SVN: r197212
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/semantics.c4
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/rv-this.C7
4 files changed, 19 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2b02880..b0a952a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2013-03-28 Jason Merrill <jason@redhat.com>
+ PR c++/56701
+ * semantics.c (finish_this_expr): 'this' is an rvalue.
+ * typeck.c (cp_build_indirect_ref): Handle NOP_EXPR of 'this'.
+
PR c++/56710
* semantics.c (finish_member_declaration): Don't push closure
members.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index ad1c209..2fe2908 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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;
}
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 4b6468c..90c7ce4 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-this.C b/gcc/testsuite/g++.dg/cpp0x/rv-this.C
new file mode 100644
index 0000000..8064a51
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-this.C
@@ -0,0 +1,7 @@
+// PR c++/56701
+// { dg-require-effective-target c++11 }
+
+struct A
+{
+ void f(){ A*&& a = this; }
+};