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
This commit is contained in:
Jakub Jelinek 2012-10-26 22:30:35 +02:00 committed by Jakub Jelinek
parent 73f4149137
commit c7a918f192
4 changed files with 29 additions and 5 deletions

View 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

View 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);

View 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.

View File

@ -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" } }