aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-05-04 21:33:33 -0400
committerJason Merrill <jason@redhat.com>2021-05-07 12:10:07 -0400
commit7a5dd3ed49d1b328865520ee30e758158516ca2b (patch)
tree70e590826b8ec89bb93ba3f9d2b5166a4354be1a /gcc
parentfc178519771db508c03611cff4a1466cf67fce1d (diff)
downloadgcc-7a5dd3ed49d1b328865520ee30e758158516ca2b.zip
gcc-7a5dd3ed49d1b328865520ee30e758158516ca2b.tar.gz
gcc-7a5dd3ed49d1b328865520ee30e758158516ca2b.tar.bz2
c++: reject class lvalues in 'rvalue'
Wrapping a class lvalue in NON_LVALUE_EXPR is not sufficient to make it a usable prvalue; callers must use force_rvalue instead. gcc/cp/ChangeLog: * tree.c (rvalue): Assert expr is not a class lvalue.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/tree.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 4ccd7a3..7f148b4 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -940,7 +940,12 @@ rvalue (tree expr)
/* We need to do this for rvalue refs as well to get the right answer
from decltype; see c++/36628. */
if (!processing_template_decl && glvalue_p (expr))
- expr = build1 (NON_LVALUE_EXPR, type, expr);
+ {
+ /* But don't use this function for class lvalues; use move (to treat an
+ lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
+ gcc_checking_assert (!CLASS_TYPE_P (type));
+ expr = build1 (NON_LVALUE_EXPR, type, expr);
+ }
else if (type != TREE_TYPE (expr))
expr = build_nop (type, expr);