]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/36089 (Funny rejects valid with constant integral expression)
authorRichard Guenther <rguenther@suse.de>
Fri, 10 Jul 2009 15:55:04 +0000 (15:55 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 10 Jul 2009 15:55:04 +0000 (15:55 +0000)
2009-07-10  Richard Guenther  <rguenther@suse.de>

Backport from mainline
2008-11-17  Jakub Jelinek  <jakub@redhat.com>

PR c++/36089
* init.c (constant_value_1): Handle TREE_LIST init.

  PR c++/37561
PR c++/36089
* g++.dg/template/init8.C: New test.

From-SVN: r149484

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

index a247aba286d7ba3440357e74905124366c927724..7cd01de330162b97965c499856ed5f001e973763 100644 (file)
@@ -1,3 +1,11 @@
+2009-07-10  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2008-11-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/36089
+       * init.c (constant_value_1): Handle TREE_LIST init.
+
 2009-06-25  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
index 3e6db24713759f3081b2c2375dda563946e1f8b0..4b115dd97f0da0d4250e36bf8cf4659a54f07942 100644 (file)
@@ -1636,6 +1636,15 @@ constant_value_1 (tree decl, bool integral_p)
        }
       if (init == error_mark_node)
        return decl;
+      /* Initializers in templates are generally expanded during
+        instantiation, so before that for const int i(2)
+        INIT is a TREE_LIST with the actual initializer as
+        TREE_VALUE.  */
+      if (processing_template_decl
+         && init
+         && TREE_CODE (init) == TREE_LIST
+         && TREE_CHAIN (init) == NULL_TREE)
+       init = TREE_VALUE (init);
       if (!init
          || !TREE_TYPE (init)
          || (integral_p
index 98848545a8de7d9f3aea734325b36e3899d0efad..250ae1f209e6c628d5c33c73e975db42068bb862 100644 (file)
@@ -1,3 +1,12 @@
+2009-07-10  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2008-11-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/37561
+       PR c++/36089
+       * g++.dg/template/init8.C: New test.
+
 2009-07-07  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/40328
diff --git a/gcc/testsuite/g++.dg/template/init8.C b/gcc/testsuite/g++.dg/template/init8.C
new file mode 100644 (file)
index 0000000..1bcda12
--- /dev/null
@@ -0,0 +1,68 @@
+// PR c++/36089
+// { dg-do run }
+
+extern "C" void abort ();
+
+int f ()
+{
+  const int c(2);
+  int d[c] = { 0, 0 };
+  return d[0] + sizeof d;
+}
+
+struct A
+{
+  static int f ()
+  {
+    const int c(2);
+    int d[c] = { 0, 0 };
+    return d[0] + sizeof d;
+  }
+};
+
+template <int> struct B
+{
+  static int f ()
+  {
+    const int c = 2;
+    int d[c] = { 0, 0 };
+    return d[0] + sizeof d;
+  }
+};
+
+template <int> struct C
+{
+  static int f ()
+  {
+    const int c(2);
+    int d[c] = { 0, 0 };
+    return d[0] + sizeof d;
+  }
+};
+
+template <int> struct D
+{
+  static int f ()
+  {
+    const int e(2);
+    const int c(e);
+    int d[c] = { 0, 0 };
+    return d[0] + sizeof d;
+  }
+};
+
+int
+main (void)
+{
+  int v = f ();
+  if (v != 2 * sizeof (int))
+    abort ();
+  if (v != A::f ())
+    abort ();
+  if (v != B<6>::f ())
+    abort ();
+  if (v != C<0>::f ())
+    abort ();
+  if (v != D<1>::f ())
+    abort ();
+}