The problem here was that we were tsubsting twice: first we did fold_non_dependent_expr in compute_array_index_type to try and get a constant, then because we didn't end up with a constant, we later tsubst it again. So if it didn't work out the first time, we should revert to the unfolded form.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 46d65806fd1f7532dc078887c8dea840ee39dcb6
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Mar 11 11:08:00 2011 -0500

        PR c++/47808
        * decl.c (compute_array_index_type): Discard folding
        if it didn't produce a constant.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 93c1848..f9d90ad 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7523,6 +7523,8 @@ compute_array_index_type (tree name, tree size, 
tsubst_flags_t complain)
            }
 
          size = maybe_constant_value (size);
+         if (!TREE_CONSTANT (size))
+           size = osize;
        }
 
       if (error_operand_p (size))
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/array1.C 
b/gcc/testsuite/g++.dg/cpp0x/regress/array1.C
new file mode 100644
index 0000000..629ab41
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/regress/array1.C
@@ -0,0 +1,16 @@
+// PR c++/47808
+// { dg-options -std=c++0x }
+
+template <typename T>
+inline T abs (T const & x) { return x; }
+
+template <typename T>
+void f (T)
+{
+  typedef int ai[(abs(0.1) > 0) ? 1 : -1];
+}
+
+int main()
+{
+  f(1);
+}

Reply via email to