Title
Placement new and previous initialization
Status
drafting
Section
6.7.4 [basic.indet]
Submitter
Jason Merrill

Created on 2014-09-08.00:00:00 last changed 117 months ago

Messages

Date: 2023-03-13.07:00:01

Given the following example,

  #include <new>

  int main() {
    unsigned char buf[sizeof(int)] = {};
    int *ip = new (buf) int;
    return *ip; // 0 or undefined?
  }

Should the preceding initializsation of the buffer carry over to the value of *ip? According to 6.7.4 [basic.indet] paragraph 1,

When storage for an object with automatic or dynamic storage duration is obtained, the object has an indeterminate value, and if no initialization is performed for the object, that object retains an indeterminate value until that value is replaced (7.6.19 [expr.ass]).

In this case, no new storage is being obtained for the int object created by the new-expression.

History
Date User Action Args
2014-09-08 00:00:00admincreate