shorts;// expected-note {{'s' declared without an initial value}}
long*lp=::new(&s)long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 3 {{}}
(void)lp;
}
namespacetestArrayNew{
voidf(){
shorts;// expected-note {{'s' declared without an initial value}}
char*buf=::new(&s)char[8];// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 3 {{}}
(void)buf;
}
}// namespace testArrayNew
namespacetestBufferInOtherFun{
voidf(void*place){
long*lp=::new(place)long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
(void)lp;
}
voidg(){
shortbuf;// expected-note {{'buf' declared without an initial value}}
f(&buf);// expected-note 2 {{}}
}
}// namespace testBufferInOtherFun
namespacetestArrayBuffer{
voidf(void*place){
long*lp=::new(place)long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
gptr=&gs;// expected-note {{Value assigned to 'gptr'}}
}
voidg(){
f();// expected-note 2 {{}}
long*lp=::new(gptr)long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
(void)lp;
}
}// namespace testGlobalPtrAsPlace
namespacetestRvalue{
shortgs;
void*f(){
return&gs;
}
voidg(){
long*lp=::new(f())long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(st)long;// expected-warning{{Storage provided to placement new is only 3 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(buf+2)long;// expected-warning{{Storage provided to placement new is only 4 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(buf+3)long;// expected-warning{{Storage provided to placement new is only 0 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(buf+4)long;// expected-warning{{Storage provided to placement new is only -4 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(buf)long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(buf)long;// expected-warning{{Storage provided to placement new is only 6 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(buf+1)long;// expected-warning{{Storage provided to placement new is only 3 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
long*lp=::new(&buf[1][1])long;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
(void)lp;
}
}// namespace testMultiDimensionalArray3
namespacetestHierarchy{
structBase{
chara[2];
};
structDerived:Base{
charx[2];
inty;
};
voidf(){
Baseb;// expected-note {{'b' initialized here}}
Derived*dp=::new(&b)Derived;// expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
::new(buffer1)S[N];// expected-warning{{Storage provided to placement new is only 64 bytes, whereas the allocated array type requires more space for internal needs}} expected-note 1 {{}}
::new(buffer2)S[N];// expected-warning{{68 bytes is possibly not enough for array allocation which requires 64 bytes. Current overhead requires the size of 4 bytes}} expected-note 1 {{}}
}
}// namespace testArrayTypesAllocation
namespacetestStructAlign{
voidf1(){
structX{
chara[9];
}Xi;// expected-note {{'Xi' initialized here}}
// bad (struct X is aligned to char).
::new(&Xi.a)long;// expected-warning{{Storage type is aligned to 1 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
}
voidf2(){
structX{
chara;
charb;
longc;
}Xi;
// ok (struct X is aligned to long).
::new(&Xi.a)long;
}
voidf3(){
structX{
chara;
charb;
longc;
}Xi;// expected-note {{'Xi' initialized here}}
// bad (struct X is aligned to long but field 'b' is aligned to 1 because of its offset)
::new(&Xi.b)long;// expected-warning{{Storage type is aligned to 1 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
}
voidf4(){
structX{
chara;
structalignas(alignof(short))Y{
charb;
charc;
}y;
longd;
}Xi;// expected-note {{'Xi' initialized here}}
// bad. 'b' is aligned to short
::new(&Xi.y.b)long;// expected-warning{{Storage type is aligned to 2 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}