On Fri, May 25, 2018 at 4:08 PM, Jason Merrill <ja...@redhat.com> wrote:
> On Fri, May 25, 2018 at 12:40 PM, Sudakshina Das <sudi....@arm.com> wrote:
>> On 23/05/18 18:21, Jason Merrill wrote:
>>>
>>> The first patch implements the adjustments from core issues 616 and
>>> 1213 to the value category of subobjects of class prvalues: they were
>>> considered prvalues themselves, but that was kind of nonsensical.  Now
>>> they are considered xvalues.  Along with this, I've removed the
>>> diagnostic distinction between xvalues and prvalues when trying to use
>>> one or the other as an lvalue; the important thing is that they are
>>> rvalues.
>>>
>>> The second patch corrects various issues with casts and xvalues/rvalue
>>> references: we were treating an xvalue operand to dynamic_cast as an
>>> lvalue, and we were objecting to casts from prvalue to rvalue
>>> reference type.
>>>
>>
>> With the second patch:
>> commit f7d2790049fd1e59af4b69ee12f7c101cfe4cdab
>> Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
>> Date:   Wed May 23 17:21:39 2018 +0000
>>
>>         Fix cast to rvalue reference from prvalue.
>>
>>         * cvt.c (diagnose_ref_binding): Handle rvalue reference.
>>         * rtti.c (build_dynamic_cast_1): Don't try to build a reference to
>>         non-class type.  Handle xvalue argument.
>>         * typeck.c (build_reinterpret_cast_1): Allow cast from prvalue to
>>         rvalue reference.
>>         * semantics.c (finish_compound_literal): Do direct-initialization,
>>         not cast, to initialize a reference.
>>
>>     git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260622
>> 138bc75d-0d04-0410-961f-82ee72b054a4
>>
>> I have observed the following failure in Spec2017 while building
>> 510.parest_r on aarch64-none-linux-gnu
>>
>> aarch64-none-linux-gnu-g++ -c -o source/numerics/matrices.all_dimensions.o
>> -DSPEC -DNDEBUG -Iinclude -I. -DSPEC_AUTO_SUPPRESS_OPENMP
>> -mcpu=cortex-a57+crypto -Ofast -fomit-frame-pointer     -fpermissive
>> -DSPEC_LP64 source/numerics/matrices.all_dimensions.cc
>>
>> source/numerics/matrices.all_dimensions.cc: In static member function
>> 'static void dealii::MatrixTools::apply_boundary_values(const
>> std::map<unsigned int, double>&, dealii::BlockSparseMatrix<number>&,
>> dealii::BlockVector<number>&, dealii::BlockVector<number>&, bool)':
>>
>> source/numerics/matrices.all_dimensions.cc:469:50: error: lvalue required as
>> unary '&' operand
>>
>>         [this_sparsity.get_rowstart_indices()[row]];
>>
>>                                                   ^
>>
>> source/numerics/matrices.all_dimensions.cc:472:55: error: lvalue required as
>> unary '&' operand
>>
>>            [this_sparsity.get_rowstart_indices()[row]+1],
>>
>>                                                        ^
>>
>> source/numerics/matrices.all_dimensions.cc:474:55: error: lvalue required as
>> unary '&' operand
>>
>>            [this_sparsity.get_rowstart_indices()[row+1]],
>>
>>                                                        ^
>>
>> source/numerics/matrices.all_dimensions.cc:479:49: error: lvalue required as
>> unary '&' operand
>>
>>        [this_sparsity.get_rowstart_indices()[row]],
>>
>>                                                  ^
>>
>> source/numerics/matrices.all_dimensions.cc:481:51: error: lvalue required as
>> unary '&' operand
>>
>>        [this_sparsity.get_rowstart_indices()[row+1]],
>>
>>                                                    ^
>>
>> source/numerics/matrices.all_dimensions.cc:510:50: error: lvalue required as
>> unary '&' operand
>>
>>           [this_sparsity.get_rowstart_indices()[0]]);
>>
>> Sudi
>
> Thanks, investigating.

Fixed thus.
commit 2c71bc15d22c4b831ff2e27ef7759de4dc78ef6c
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri May 25 16:25:10 2018 -0400

            CWG 616, 1213 - value category of subobject references.
    
            * tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer.

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 <class T> 
+void f(int i)
+{
+  int *p = &g()[3];
+}

Reply via email to