Remove references taken from temporaries returned by Variant::get()
- Dominant language
- C++
- Stars
- 161
- Forks
- 59
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 7
Description
**Describe the bug**
In the light [```Variant```](https://github.com/openPMD/openPMD-api/blob/0.2.0-alpha/include/openPMD/auxiliary/Variant.hpp) wrapper, values retieved with [```Varaiant::get()```](https://github.com/openPMD/openPMD-api/blob/0.2.0-alpha/include/openPMD/auxiliary/Variant.hpp#L62-L72) are returned as a copy of the underlying resource.
At some point during development, I assumed it returned references to the underlying resources. In [multiple](https://github.com/openPMD/openPMD-api/blob/aca17f8563e53841b3bbb44a05a2a9e7cb3afb7d/src/backend/PatchRecord.cpp#L65) [places](https://github.com/openPMD/openPMD-api/blob/b8e8de9187e7cc179589c974d042de9cf3ae92b4/src/backend/MeshRecordComponent.cpp#L46) [throughout](https://github.com/openPMD/openPMD-api/blob/265828b7f79428e2cf3caa3e9252b03c0f29f1c9/src/IO/ADIOS/ADIOS1IOHandler.cpp#L844) the code, references are taken from the returned values.
This is undefined behaviour w.r.t. the C++ standard, as the references taken from temporaries are dangling as soon as the temporary goes out of scope.
**Expected behavior**
Do not have undefiend behaviour in the code using ```Variant::get()```.
Either make it return a ```U const&``` (which may result in the same problem) or adapt the code using it.
Contributor guide
Assessment
This issue has not been assessed yet.