newMyLongPointerFromConversion(MyLongOwnerWithConversion{});// expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
newMyIntPointer(MyIntOwner{});// expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
}
voidintentionalFalseNegative(){
inti;
MyIntPointerp{&i};
// In this case we do not have enough information in a statement local
// analysis to detect the problem.
newMyIntPointer(p);
newMyIntPointer(MyIntPointer{p});
}
MyIntPointerownershipTransferToMyPointer(){
MyLongOwnerWithConversiont;
returnt.releaseAsMyPointer();// ok
}
long*ownershipTransferToRawPointer(){
MyLongOwnerWithConversiont;
returnt.releaseAsRawPointer();// ok
}
structY{
inta[4];
};
voiddangligGslPtrFromTemporary(){
MyIntPointerp=Y{}.a;// expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}}
(void)p;
}
structDanglingGslPtrField{
MyIntPointerp;// expected-note 2{{pointer member declared here}}
MyLongPointerFromConversionp2;// expected-note {{pointer member declared here}}
DanglingGslPtrField(inti):p(&i){}// expected-warning {{initializing pointer member 'p' with the stack address of parameter 'i'}}
DanglingGslPtrField():p2(MyLongOwnerWithConversion{}){}// expected-warning {{initializing pointer member 'p2' to point to a temporary object whose lifetime is shorter than the lifetime of the constructed object}}
DanglingGslPtrField(double):p(MyIntOwner{}){}// expected-warning {{initializing pointer member 'p' to point to a temporary object whose lifetime is shorter than the lifetime of the constructed object}}
};
MyIntPointerdanglingGslPtrFromLocal(){
intj;
return&j;// expected-warning {{address of stack memory associated with local variable 'j' returned}}
}
MyIntPointerreturningLocalPointer(){
MyIntPointerlocalPointer;
returnlocalPointer;// ok
}
MyIntPointerdaglingGslPtrFromLocalOwner(){
MyIntOwnerlocalOwner;
returnlocalOwner;// expected-warning {{address of stack memory associated with local variable 'localOwner' returned}}
returnMyLongOwnerWithConversion{};// expected-warning {{returning address of local temporary object}}
}
int*noFalsePositive(MyIntOwner&o){
MyIntPointerp=o;
return&*p;// ok
}
MyIntPointerglobal;
MyLongPointerFromConversionglobal2;
voidinitLocalGslPtrWithTempOwner(){
MyIntPointerp=MyIntOwner{};// expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
p=MyIntOwner{};// TODO ?
global=MyIntOwner{};// TODO ?
MyLongPointerFromConversionp2=MyLongOwnerWithConversion{};// expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
std::vector<int>::iteratorit=std::vector<int>().begin();// expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}