openPMD / openPMD-api

:floppy_disk: C++ & Python API for Scientific I/O
https://openpmd-api.readthedocs.io
GNU Lesser General Public License v3.0
138 stars 51 forks source link

ADIOS1 Destructors Must Not Throw #550

Open ax3l opened 5 years ago

ax3l commented 5 years ago

Describe the bug Destructors may not fail in clean C++, which otherwise makes object destruction and associated resource occupation unreliable. Also given by C++ core guidelines.

To Reproduce Compile the project with clang-tidy-7 or newer with enabled ADIOS1 backend. The warning bugprone-exception-escape will be visible in ParallelADIOS1IOHandlerImpl::~ParallelADIOS1IOHandlerImpl() (src/IO/ADIOS/ParallelADIOS1IOHandler.cpp) and ADIOS1IOHandlerImpl::~ADIOS1IOHandlerImpl() (src/IO/ADIOS/ADIOS1IOHandler.cpp).

Example:

# in directory $HOME/src/openPMD-api
mkdir build && cd build

CXX=clang++-7 CC=clang-7 cmake -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy-7);-system-headers=0" -DCMAKE_CXX_STANDARD=17 -DopenPMD_USE_PYTHON=OFF ..
make

Expected behavior A clear and concise description of what you expected to happen.

Software Environment

sbastrakov commented 5 years ago

I do not have an easy way to fix now, but the destructors call flush_attribute() containing this line, not sure if it is the only violator.

Edit: I mean, ofc that call or even the whole bodies of the destructors in question could be put to try-catch, if that counts as a solution.

ax3l commented 5 years ago

Yes, there are several solutions for that. FWIW, the PHDF5 backend destructor solves the same problem gracefully, e.g. by writing to std::cerr instead of throwing.