aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r--gcc/cp/init.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 7386499d570..b45281f517d 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2321,12 +2321,14 @@ warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
if (TREE_CODE (oper) == POINTER_PLUS_EXPR)
{
/* If the offset is comple-time constant, use it to compute a more
- accurate estimate of the size of the buffer. Otherwise, use
- the size of the entire array as an optimistic estimate (this
- may lead to false negatives). */
- const_tree adj = TREE_OPERAND (oper, 1);
+ accurate estimate of the size of the buffer. Since the operand
+ of POINTER_PLUS_EXPR is represented as an unsigned type, convert
+ it to signed first.
+ Otherwise, use the size of the entire array as an optimistic
+ estimate (this may lead to false negatives). */
+ tree adj = TREE_OPERAND (oper, 1);
if (CONSTANT_CLASS_P (adj))
- adjust += tree_to_uhwi (adj);
+ adjust += tree_to_shwi (convert (ssizetype, adj));
else
use_obj_size = true;
@@ -2447,7 +2449,7 @@ warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
"%<%T [%wu]%> and size %qwu in a region of type %qT "
"and size %qwi"
: "placement new constructing an object of type "
- "%<%T [%lu]%> and size %qwu in a region of type %qT "
+ "%<%T [%wu]%> and size %qwu in a region of type %qT "
"and size at most %qwu",
type, tree_to_uhwi (nelts), bytes_need,
TREE_TYPE (oper),