re PR c++/19270 (ice on valid template code)
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 6 Jan 2005 15:22:11 +0000 (15:22 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 6 Jan 2005 15:22:11 +0000 (15:22 +0000)
cp:
PR c++/19270
* pt.c (tsubst_copy) <ARRAY_REF case>: Handle separately.
(tsubst_copy_and_build) <ARRAY_REF case>: Remove obsolete
array-new handling code.  Use build_x_binary_op.
testsuite:
PR c++/19270
* g++.dg/template/array10.C: New.

From-SVN: r92992

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/array10.C [new file with mode: 0644]

index 4f3e21003e8d0686e5aaeed0dff6b2f0e87d058e..fb98595db1fb05a90704b3b45be2839c286d8d53 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-06  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/19270
+       * pt.c (tsubst_copy) <ARRAY_REF case>: Handle separately.
+       (tsubst_copy_and_build) <ARRAY_REF case>: Remove obsolete
+       array-new handling code.  Use build_x_binary_op.
+
 2005-01-05  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/19030
index f24865e8f108e7fc572dfbd124fb6c0748292101..e6f4b51098f364a31e593425e8701cf0c57c8462 100644 (file)
@@ -7869,7 +7869,6 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     case GE_EXPR:
     case LT_EXPR:
     case GT_EXPR:
-    case ARRAY_REF:
     case COMPOUND_EXPR:
     case SCOPE_REF:
     case DOTSTAR_EXPR:
@@ -7882,6 +7881,13 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
        (code, tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl),
         tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl));
 
+    case ARRAY_REF:
+      return build_nt
+       (ARRAY_REF,
+        tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl),
+        tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl),
+        NULL_TREE, NULL_TREE);
+
     case CALL_EXPR:
       return build_nt (code, 
                       tsubst_copy (TREE_OPERAND (t, 0), args,
@@ -8526,21 +8532,12 @@ tsubst_copy_and_build (tree t,
     case SCOPE_REF:
       return tsubst_qualified_id (t, args, complain, in_decl, /*done=*/true,
                                  /*address_p=*/false);
-
     case ARRAY_REF:
-      if (tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl)
-         == NULL_TREE)
-       /* new-type-id */
-       return build_nt (ARRAY_REF, NULL_TREE, RECUR (TREE_OPERAND (t, 1)),
-                        NULL_TREE, NULL_TREE);
-
       op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
                                                args, complain, in_decl);
-      /* Remember that there was a reference to this entity.  */
-      if (DECL_P (op1))
-       mark_used (op1);
-      return grok_array_decl (op1, RECUR (TREE_OPERAND (t, 1)));
-
+      return build_x_binary_op (ARRAY_REF, op1, RECUR (TREE_OPERAND (t, 1)),
+                               /*overloaded_p=*/NULL);
+      
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
       op1 = TREE_OPERAND (t, 0);
index 63b3ac167dd471083bdeb7ef9cf6634e80a4d08c..139d695f2ae0b23208d30eee74d8a9c998628b32 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-06  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/19270
+       * g++.dg/template/array10.C: New.
+
 2005-01-05  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * g++.old-deja/g++.pt/asm1.C, g++.old-deja/g++.pt/asm2.C,
diff --git a/gcc/testsuite/g++.dg/template/array10.C b/gcc/testsuite/g++.dg/template/array10.C
new file mode 100644 (file)
index 0000000..81aac84
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (C) 2005 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 5 Jan 2005 <nathan@codesourcery.com>
+
+// PR 19270: ICE
+// Origin:  Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+template<class T> struct Vec {
+  T* data;
+  T& operator[](int i) const;
+};
+
+template<class T> inline T& Vec<T>::operator[](int i) const
+{
+  return (&data[0])[i];
+}
+
+inline double foo(Vec<double> v)
+{
+  return v[0];
+}