summaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-20 02:48:43 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-20 02:48:43 +0000
commitf16ed232f63165d926986d482708ebf464a04108 (patch)
treea3ee54d747eb001c8c79a026521c8920f2221b27 /gcc/cp/constexpr.c
parenta349de0a9fefcf144a65d3403099e3f7b6f45730 (diff)
downloadgcc-f16ed232f63165d926986d482708ebf464a04108.tar.gz
Expand PTRMEM_CST only when necessary.
* constexpr.c (cxx_eval_constant_expression): Expand PTRMEM_CST only when necessary. (cxx_eval_component_reference): Like here. * decl2.c (lower_var_init): And here. (c_parse_final_cleanups): Call it. * typeck2.c (digest_init_r): Not here. * decl.c (complete_vars): Or here. (cp_finish_decl): Add local statics to symbol table. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229018 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 1bb8efa90ed..3d682fd23f2 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1863,6 +1863,8 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
tree whole = cxx_eval_constant_expression (ctx, orig_whole,
lval,
non_constant_p, overflow_p);
+ if (TREE_CODE (whole) == PTRMEM_CST)
+ whole = cplus_expand_constant (whole);
if (whole == orig_whole)
return t;
if (lval)
@@ -3129,9 +3131,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
}
if (CONSTANT_CLASS_P (t))
{
- if (TREE_CODE (t) == PTRMEM_CST)
- t = cplus_expand_constant (t);
- else if (TREE_OVERFLOW (t) && (!flag_permissive || ctx->quiet))
+ if (TREE_OVERFLOW (t) && (!flag_permissive || ctx->quiet))
*overflow_p = true;
return t;
}
@@ -3545,7 +3545,11 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
non_constant_p, overflow_p);
if (*non_constant_p)
return t;
- if (POINTER_TYPE_P (TREE_TYPE (t))
+ tree type = TREE_TYPE (t);
+ if (TREE_CODE (op) == PTRMEM_CST
+ && !TYPE_PTRMEM_P (type))
+ op = cplus_expand_constant (op);
+ if (POINTER_TYPE_P (type)
&& TREE_CODE (op) == INTEGER_CST
&& !integer_zerop (op))
{
@@ -3559,7 +3563,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
/* We didn't fold at the top so we could check for ptr-int
conversion. */
return fold (t);
- r = fold_build1 (TREE_CODE (t), TREE_TYPE (t), op);
+ r = fold_build1 (TREE_CODE (t), type, op);
/* Conversion of an out-of-range value has implementation-defined
behavior; the language considers it different from arithmetic
overflow, which is undefined. */