]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/55081 (Non-optimized static array elements initialization)
authorJakub Jelinek <jakub@redhat.com>
Fri, 26 Oct 2012 20:30:35 +0000 (22:30 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 26 Oct 2012 20:30:35 +0000 (22:30 +0200)
PR c++/55081
* typeck2.c (store_init_value): Call fold_non_dependent_expr
and maybe_constant_init even for C++98.

* g++.dg/opt/pr55081.C: New test.

From-SVN: r192862

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr55081.C [new file with mode: 0644]

index 1a94fb366bd282ec69084e0aaa0587f285a55986..86050dafde3317b9257cba4972883df5c19b2699 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/55081
+       * typeck2.c (store_init_value): Call fold_non_dependent_expr
+       and maybe_constant_init even for C++98.
+
 2012-10-26  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/54984
index 3dbfcb6663a09b9ff65acae8f81201a438edc465..3478886dea1c6391b83fcd5687ac25db0fc9b3f7 100644 (file)
@@ -709,11 +709,9 @@ store_init_value (tree decl, tree init, VEC(tree,gc)** cleanups, int flags)
 
   /* In C++0x constant expression is a semantic, not syntactic, property.
      In C++98, make sure that what we thought was a constant expression at
-     template definition time is still constant.  */
-  if ((cxx_dialect >= cxx0x
-       || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
-      && (decl_maybe_constant_var_p (decl)
-         || TREE_STATIC (decl)))
+     template definition time is still constant and otherwise perform this
+     as optimization, e.g. to fold SIZEOF_EXPRs in the initializer.  */
+  if (decl_maybe_constant_var_p (decl) || TREE_STATIC (decl))
     {
       bool const_init;
       value = fold_non_dependent_expr (value);
index b3b6facf1c658997f7f6f718c563aba247777d4c..90946d29b12510b1fa1a2e4425b6289653559ca1 100644 (file)
@@ -1,5 +1,8 @@
 2012-10-26  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/55081
+       * g++.dg/opt/pr55081.C: New test.
+
        PR debug/54970
        PR debug/54971
        * gcc.dg/guality/pr54970.c: New test.
diff --git a/gcc/testsuite/g++.dg/opt/pr55081.C b/gcc/testsuite/g++.dg/opt/pr55081.C
new file mode 100644 (file)
index 0000000..b4f533e
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/55081
+// { dg-do compile }
+
+struct R { int field; } r;
+
+__UINTPTR_TYPE__ *
+foo ()
+{
+  static __UINTPTR_TYPE__ array[] = {
+    sizeof (char),
+    (reinterpret_cast <__UINTPTR_TYPE__>(&r.field)
+     - reinterpret_cast <__UINTPTR_TYPE__>(&r)) + 1
+  };
+  return array;
+}
+
+// { dg-final { scan-assembler-not "_ZGVZ3foovE5array" } }