Bug with KVNameValueList(std::initializer_list) constructor
The following code goes badly awry:
void copy_my_list(const KVNameValueList& nvl)
{
std::cout << "copy_my_list\n";
KVNameValueList copylist(nvl);
copylist.ls();
}
void test()
{
KVNameValueList A{{"Name","Bernard"}};
copy_my_list(A);
A.ls();
}
kaliveda[0] test()
copy_my_list
KVNameValueList : Name=Bernard
*** Break *** segmentation violation
KVNameValueList :
because in the std::initializer_list constructor the underlying KVHashList which contains all the parameters of the list was not made the owner of its objects, therefore in the copy constructor only a shallow copy of the list is made (copies the addresses of the existing objects), then (bizarrely - no need to do this) at the end of the copy constructor the KVHashList of the new copy is set to owning: it therefore deletes the parameters of its 'parent' list which is left with a list of stale pointers.
Edited by John Frankland