aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2003-12-29 17:02:03 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2003-12-29 17:02:03 +0000
commit30a035080e17df2e1b21322d398532b30af80cd1 (patch)
treec3923f14a15451d884b19950367d2be72de87c79
parentb66906a8ff79931bc3d23b9362833b1567c5ac56 (diff)
downloadgcc-30a035080e17df2e1b21322d398532b30af80cd1.zip
gcc-30a035080e17df2e1b21322d398532b30af80cd1.tar.gz
gcc-30a035080e17df2e1b21322d398532b30af80cd1.tar.bz2
re PR c++/12774 (Type checking problems in templates)
cp: PR c++/12774 * typeck.c (comp_array_types): Fold non-dependent domains for ABI-1. testsuite: PR c++/12774 * g++.dg/template/array1-1.C: New test. * g++.dg/template/array1-2.C: New test. From-SVN: r75204
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c24
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/template/array1-1.C32
-rw-r--r--gcc/testsuite/g++.dg/template/array1-2.C32
5 files changed, 98 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 72c0f5f..1d61141 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-29 Nathan Sidwell <nathan@codesourcery.com>
+
+ PR c++/12774
+ * typeck.c (comp_array_types): Fold non-dependent domains for
+ ABI-1.
+
2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13289
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 3cdfdc2..ff397c0 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -857,6 +857,7 @@ comp_array_types (tree t1, tree t2, bool allow_redeclaration)
{
tree d1;
tree d2;
+ tree max1, max2;
if (t1 == t2)
return true;
@@ -887,8 +888,27 @@ comp_array_types (tree t1, tree t2, bool allow_redeclaration)
return allow_redeclaration;
/* Check that the dimensions are the same. */
- return (cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
- && cp_tree_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)));
+
+ if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
+ return false;
+ max1 = TYPE_MAX_VALUE (d1);
+ max2 = TYPE_MAX_VALUE (d2);
+ if (processing_template_decl && !abi_version_at_least (2)
+ && !value_dependent_expression_p (max1)
+ && !value_dependent_expression_p (max2))
+ {
+ /* With abi-1 we do not fold non-dependent array bounds, (and
+ consequently mangle them incorrectly). We must therefore
+ fold them here, to verify the domains have the same
+ value. */
+ max1 = fold (max1);
+ max2 = fold (max2);
+ }
+
+ if (!cp_tree_equal (max1, max2))
+ return false;
+
+ return true;
}
/* Return true if T1 and T2 are related as allowed by STRICT. STRICT
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9f57557..be64671 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-29 Nathan Sidwell <nathan@codesourcery.com>
+
+ PR c++/12774
+ * g++.dg/template/array1-1.C: New test.
+ * g++.dg/template/array1-2.C: New test.
+
2003-12-29 Roger Sayle <roger@eyesopen.com>
PR fortran/12632
diff --git a/gcc/testsuite/g++.dg/template/array1-1.C b/gcc/testsuite/g++.dg/template/array1-1.C
new file mode 100644
index 0000000..97fe7cd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/array1-1.C
@@ -0,0 +1,32 @@
+// { dg-do compile }
+// { dg-options "-fabi-version=1" }
+
+// Contributed by Nathan Sidwell 22 Dec 2003 <nathan@codesourcery.com>
+// Origin: Roger Sayle <roger@eyesopen.com>
+
+// PR c++/12774 Array domains compared unequal
+
+void Foo(double r[3][3])
+{
+}
+
+void Baz()
+{
+ double m[3][3];
+ Foo(m);
+}
+
+template <class T>
+void Bar()
+{
+ double m[3][3];
+ Foo(m);
+}
+
+int main()
+{
+ Baz();
+ Bar<int>();
+ return 0;
+}
+
diff --git a/gcc/testsuite/g++.dg/template/array1-2.C b/gcc/testsuite/g++.dg/template/array1-2.C
new file mode 100644
index 0000000..7214517
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/array1-2.C
@@ -0,0 +1,32 @@
+// { dg-do compile }
+// { dg-options "-fabi-version=2" }
+
+// Contributed by Nathan Sidwell 22 Dec 2003 <nathan@codesourcery.com>
+// Origin: Roger Sayle <roger@eyesopen.com>
+
+// PR c++/12774 Array domains compared unequal
+
+void Foo(double r[3][3])
+{
+}
+
+void Baz()
+{
+ double m[3][3];
+ Foo(m);
+}
+
+template <class T>
+void Bar()
+{
+ double m[3][3];
+ Foo(m);
+}
+
+int main()
+{
+ Baz();
+ Bar<int>();
+ return 0;
+}
+