SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

Make soci_error nothrow copy constructible #1042

Closed zann1x closed 1 year ago

zann1x commented 1 year ago

According to the CERT C++ Coding Standard rule ERR60-CPP. Exception objects must be nothrow copy constructible, SOCI's base exception soci_error should have noexcept copy constructors. The exception classes derived from soci_error don't have copy constructors, i.e. they adhere to this rule automatically.

zann1x commented 1 year ago

I switched to the copy-and-swap implementation based on OOP54-CPP. Gracefully handle self-copy assignment. Alternatively, I think that we should at least check for self-assignment in the copy constructor.

I don't have a strong opinion about it, though. So if you think we should keep the old copy logic, I'll happily revert that part.

vadz commented 1 year ago

Oops, embarrassing not to have noticed that we had a self-assignment problem currently, thanks for pointing this out. I agree that this should be fixed, but I still think that if we change it like this we'd also need to change the ctor to avoid having the not very useful make_safe_copy(). So adding a check for &e == this would still be simpler...

zann1x commented 1 year ago

Sure thing, let's do &e == this then.

I don't have access to my workstation until monday, so you'll have to wait a bit :)

vadz commented 1 year ago

Sorry for the delay, finally merged, thanks again!