This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix rejects-valid with value dependent array size (PR c++/33553)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 4 Feb 2008 10:21:01 -0500
- Subject: [C++ PATCH] Fix rejects-valid with value dependent array size (PR c++/33553)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
PR28595 added a check that when not at function scope
array bounds should must be integral constants expressions
(at function scope, when not in a local class, g++ allows VLAs
when not pedantic). But if max is still value dependent during
tsubst, this rejected valid code as shown on the attached testcase.
Regtested on x86_64-linux, ok for trunk?
2008-02-04 Jakub Jelinek <jakub@redhat.com>
PR c++/33553
* pt.c (tsubst) <case INTEGER_TYPE>: Don't issue error if max is
value dependent expression.
* g++.dg/template/array19.C: New test.
--- gcc/cp/pt.c.jj 2008-02-04 15:46:52.000000000 +0100
+++ gcc/cp/pt.c 2008-02-04 15:47:10.000000000 +0100
@@ -8894,9 +8894,9 @@ tsubst (tree t, tree args, tsubst_flags_
/*integral_constant_expression_p=*/false);
max = fold_decl_constant_value (max);
- if (TREE_CODE (max) != INTEGER_CST
- && TREE_CODE (max) != TEMPLATE_PARM_INDEX
- && !at_function_scope_p ())
+ if (TREE_CODE (max) != INTEGER_CST
+ && !at_function_scope_p ()
+ && !value_dependent_expression_p (max))
{
if (complain & tf_error)
error ("array bound is not an integer constant");
--- gcc/testsuite/g++.dg/template/array19.C.jj 2008-02-04 15:46:22.000000000 +0100
+++ gcc/testsuite/g++.dg/template/array19.C 2008-02-04 15:41:22.000000000 +0100
@@ -0,0 +1,22 @@
+// PR c++/33553
+// { dg-do compile }
+
+template <class T> struct S { static const int sz = 2; };
+template <class T> struct U { enum { sz = 2 }; };
+
+template <class R>
+struct P
+{
+ template <class T> void bar (int (&x)[S<T>::sz]);
+ template <class T> void baz (int (&x)[U<T>::sz]);
+};
+
+P<int> p;
+
+void
+foo (void)
+{
+ int x[2];
+ p.bar<int> (x);
+ p.baz<int> (x);
+}
Jakub