aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2012-10-26 22:30:35 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2012-10-26 22:30:35 +0200
commitc7a918f192a9ab425d2531e15e36bf80fac17ef8 (patch)
tree89d72c8e65e639e19213af9f210318c7176ab5a6 /gcc
parent73f4149137364da5b6d1238720b7fc21226b5b27 (diff)
downloadgcc-c7a918f192a9ab425d2531e15e36bf80fac17ef8.zip
gcc-c7a918f192a9ab425d2531e15e36bf80fac17ef8.tar.gz
gcc-c7a918f192a9ab425d2531e15e36bf80fac17ef8.tar.bz2
re PR c++/55081 (Non-optimized static array elements initialization)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck2.c8
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/opt/pr55081.C17
4 files changed, 29 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1a94fb3..86050da 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 3dbfcb6..3478886 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b3b6fac..90946d2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..b4f533e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr55081.C
@@ -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" } }