Hi Community,
I have a question regarding the rule cpp:S5018: move operations should be noexcept.
We see it from time to time in our codebase whenever we compose our own data structure from std containers (mostly std::map, but also std::list is not noexcept movable).
So if I have in the simplest case:
struct A {
std::map<int, X> entries;
}
the rule would flag it. I can’t think of a proper solution though to make the move operation noexcept.
On the other hand, forbidding the move operation seems to be a drastic intervention as well. If the STL data structures don’t comply to this advice from the rule description: “If you can not implement your move operations so that they never throw, you may only provide copy operations that will be safer to use.”, why should I try to do so in my custom code? In these cases I stick with the rule-of-zero advice and set the sonar issue to won’t fix.
Curious though to hear how other users solve these situations.
I’m currently on sonarqube server v2025.1.1.