From 3983063e76edec0a49badb341daa1ba438c5a9a7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 25 May 2018 16:55:32 -0400 Subject: [PATCH] CWG 616, 1213 - value category of subobject references. * tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer. From-SVN: r260780 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/tree.c | 24 +++++++++++++++++------- gcc/testsuite/g++.dg/template/array31.C | 7 +++++++ 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/array31.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 371c8b7..9c2548d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-05-25 Jason Merrill + + CWG 616, 1213 - value category of subobject references. + * tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer. + 2018-05-24 Jason Merrill PR c++/85842 - -Wreturn-type, constexpr if and generic lambda. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 9d97816..f21daac 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -95,14 +95,24 @@ lvalue_kind (const_tree ref) case TRY_CATCH_EXPR: case REALPART_EXPR: case IMAGPART_EXPR: - case ARRAY_REF: case VIEW_CONVERT_EXPR: - op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); - if (op1_lvalue_kind == clk_class) - /* in the case of an array operand, the result is an lvalue if that - operand is an lvalue and an xvalue otherwise */ - op1_lvalue_kind = clk_rvalueref; - return op1_lvalue_kind; + return lvalue_kind (TREE_OPERAND (ref, 0)); + + case ARRAY_REF: + { + tree op1 = TREE_OPERAND (ref, 0); + if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE) + { + op1_lvalue_kind = lvalue_kind (op1); + if (op1_lvalue_kind == clk_class) + /* in the case of an array operand, the result is an lvalue if + that operand is an lvalue and an xvalue otherwise */ + op1_lvalue_kind = clk_rvalueref; + return op1_lvalue_kind; + } + else + return clk_ordinary; + } case MEMBER_REF: case DOTSTAR_EXPR: diff --git a/gcc/testsuite/g++.dg/template/array31.C b/gcc/testsuite/g++.dg/template/array31.C new file mode 100644 index 0000000..007d0dc --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array31.C @@ -0,0 +1,7 @@ +int *g(); + +template +void f(int i) +{ + int *p = &g()[3]; +} -- 2.7.4