From: Jason Merrill Date: Fri, 25 May 2018 20:55:32 +0000 (-0400) Subject: CWG 616, 1213 - value category of subobject references. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3983063e76edec0a49badb341daa1ba438c5a9a7;p=gcc.git CWG 616, 1213 - value category of subobject references. * tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer. From-SVN: r260780 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 371c8b76fef..9c2548d5377 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 9d978160292..f21daaca1d0 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 00000000000..007d0dccf89 --- /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]; +}