re PR c++/34397 (ICE on invalid default template parameter)
authorPaolo Carlini <paolo@gcc.gnu.org>
Tue, 10 Feb 2009 21:47:12 +0000 (21:47 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 10 Feb 2009 21:47:12 +0000 (21:47 +0000)
/cp
2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/34397
* typeck.c (build_x_array_ref): New.
* cp-tree.h: Declare it.
* pt.c (tsubst_copy_and_build): Use it for case ARRAY_REF.

/testsuite
2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/34397
* g++.dg/template/crash88.C: New.
* g++.dg/template/crash89.C: Likewise.

From-SVN: r144083

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/crash88.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/crash89.C [new file with mode: 0644]

index 2db00fd979b12fc2b40317200322a0fbc2e587ee..5b354374f4830eb8e46f487f3f18f90d3945c26e 100644 (file)
@@ -1,3 +1,10 @@
+2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/34397
+       * typeck.c (build_x_array_ref): New.
+       * cp-tree.h: Declare it.
+       * pt.c (tsubst_copy_and_build): Use it for case ARRAY_REF.
+
 2009-02-09  Jason Merrill  <jason@redhat.com>
 
        PR c++/39109
index 87eefa33437ef1b62753b7d6ce7a13ef0219facd..5bf8595a02618c8fe189cec0a75d1f6a8381ba9c 100644 (file)
@@ -4937,6 +4937,7 @@ extern tree build_x_binary_op                     (enum tree_code, tree,
                                                 enum tree_code, tree,
                                                 enum tree_code, bool *,
                                                 tsubst_flags_t);
+extern tree build_x_array_ref                  (tree, tree, tsubst_flags_t);
 extern tree build_x_unary_op                   (enum tree_code, tree,
                                                  tsubst_flags_t);
 extern tree cp_build_unary_op                   (enum tree_code, tree, int, 
index c5b675faa1640d56d990fae42c6010503c23eeba..3176dc2b844319e0d8395ae0031b51905fafca6f 100644 (file)
@@ -1,6 +1,7 @@
 /* Handle parameterized types (templates) for GNU C++.
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2007, 2008  Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Free Software Foundation, Inc.
    Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
    Rewritten by Jason Merrill (jason@cygnus.com).
 
@@ -11228,16 +11229,7 @@ tsubst_copy_and_build (tree t,
     case ARRAY_REF:
       op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
                                                args, complain, in_decl);
-      return build_x_binary_op (ARRAY_REF, op1,
-                               (TREE_NO_WARNING (TREE_OPERAND (t, 0))
-                                ? ERROR_MARK
-                                : TREE_CODE (TREE_OPERAND (t, 0))),
-                               RECUR (TREE_OPERAND (t, 1)),
-                               (TREE_NO_WARNING (TREE_OPERAND (t, 1))
-                                ? ERROR_MARK
-                                : TREE_CODE (TREE_OPERAND (t, 1))),
-                               /*overloaded_p=*/NULL,
-                               complain);
+      return build_x_array_ref (op1, RECUR (TREE_OPERAND (t, 1)), complain);
 
     case SIZEOF_EXPR:
       if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
index c58d40b9195563de39dfb19734b02532137ecb97..a6986f94b6352c27304a0bd3a212be1f6382d7fa 100644 (file)
@@ -3198,6 +3198,34 @@ build_x_binary_op (enum tree_code code, tree arg1, enum tree_code arg1_code,
   return expr;
 }
 
+/* Build and return an ARRAY_REF expression.  */
+
+tree
+build_x_array_ref (tree arg1, tree arg2, tsubst_flags_t complain)
+{
+  tree orig_arg1 = arg1;
+  tree orig_arg2 = arg2;
+  tree expr;
+
+  if (processing_template_decl)
+    {
+      if (type_dependent_expression_p (arg1)
+         || type_dependent_expression_p (arg2))
+       return build_min_nt (ARRAY_REF, arg1, arg2,
+                            NULL_TREE, NULL_TREE);
+      arg1 = build_non_dependent_expr (arg1);
+      arg2 = build_non_dependent_expr (arg2);
+    }
+
+  expr = build_new_op (ARRAY_REF, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
+                      /*overloaded_p=*/NULL, complain);
+
+  if (processing_template_decl && expr != error_mark_node)
+    return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
+                             NULL_TREE, NULL_TREE);
+  return expr;
+}
+
 /* For the c-common bits.  */
 tree
 build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
index 37654e71cf7f218d33898313ff516826ec37d389..fedb4c60da298c5373da9ca14c4fb154d4de043e 100644 (file)
@@ -1,7 +1,13 @@
+2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/34397
+       * g++.dg/template/crash88.C: New.
+       * g++.dg/template/crash89.C: Likewise.
+
 2009-02-10  Steve Ellcey  <sje@cup.hp.com>
 
        PR c/39084
-       gcc.dg/pr39084.c: New test.
+       gcc.dg/pr39084.c: New test.
 
 2009-02-10  Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/testsuite/g++.dg/template/crash88.C b/gcc/testsuite/g++.dg/template/crash88.C
new file mode 100644 (file)
index 0000000..438ab90
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/34397
+
+template<typename T, int = T()[0]> struct A
+{
+  typedef A<T> B;
+};
diff --git a/gcc/testsuite/g++.dg/template/crash89.C b/gcc/testsuite/g++.dg/template/crash89.C
new file mode 100644 (file)
index 0000000..e62b57a
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/34397
+
+template<typename T, int = T()[0]> struct A
+{
+  typedef A<T> B;
+};
+
+A<int> a; // { dg-error "subscripted|template|declaration" }