@@ -3206,6 +3206,11 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
cacheable = false;
break;
}
+ /* Also don't cache a call that returns a deallocated pointer. */
+ if (cacheable && CHECKING_P
+ && (cp_walk_tree_without_duplicates
+ (&result, find_heap_var_refs, NULL)))
+ cacheable = false;
}
/* Rewrite all occurrences of the function's RESULT_DECL with the
@@ -3215,10 +3220,6 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
&& !is_empty_class (TREE_TYPE (res)))
if (replace_decl (&result, res, ctx->object))
cacheable = false;
-
- /* Only cache a permitted result of a constant expression. */
- if (cacheable && !reduced_constant_expression_p (result))
- cacheable = false;
}
else
/* Couldn't get a function copy to evaluate. */
@@ -3230,6 +3231,18 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
result = error_mark_node;
else if (!result)
result = void_node;
+
+ /* Only cache a permitted result of a constant expression. */
+ if (cacheable && !reduced_constant_expression_p (result))
+ {
+ cacheable = false;
+ if (CHECKING_P
+ && result != void_node && result != error_mark_node
+ && !(TREE_CODE (result) == CONSTRUCTOR
+ && CONSTRUCTOR_NO_CLEARING (result)))
+ internal_error ("caching %qE", result);
+ }
+
if (entry)
entry->result = cacheable ? result : error_mark_node;
}