I have the following structure,
struct MyStruct{
bool myBool,
int myInt,
std::unique_ptr<boost::circular_buffer<int>> myUniquePtr;
} ;
Let's say I construct the following object,
MyStruct* myStruct = new MyStruct();
I then update the size of my buffer with
myStruct->myUniquePtr = std::make_unique<boost::circular_buffer<int>>(DIM)
where
#define DIM 8
It works as expected but my static code analyzer (Klocwork
) flags the previous line (the one with make_unique
)
LOCRET.ARG: Address of local variable is returned through formal argument
Details:
Local address "&std::make_unique<boost::circular_buffer < int > >(DIM)" is passed through 'operator=' and stored into 'myStruct->myUniquePtr._M_t'
'myStruct->myUniquePtr._M_t' can be used outside of this function
In fact, all lines relying on make_unique
yield this warning. I am wondering whether it's a false positive or not.
Minimal Reproducible Example:
struct MyStruct{
bool myBool,
int myInt,
std::unique_ptr<boost::circular_buffer<int>> myUniquePtr;
} ;
void initMyStruct(MyStruct* pStruct)
{
pStruct->myUniquePtr = std::make_unique<<boost::circular_buffer<int>>(DIM);
}
and as main:
MyStruct* myStruct = new MyStruct();
initMyStruct(myStruct);