1

In Visual Studio 2017, I'm attempting to add 'noexcept' to all relevant move constructors and move assignment operators so that they can be called by Standard Library containers.

Is there a way to find all move constructors and move assignment operators? Or is there a compiler warning to turn on if a move constructor/assignment operator is not flagged with 'noexcept'?

Coder_Dan
  • 1,815
  • 3
  • 23
  • 31
  • You should add some code, what kind of class are you creating, what are its uses? – HangrY Mar 21 '18 at 10:47
  • Ideally you should have no user defined move constructors and move assignment operators, or close to none. You should follow the rule of 0. – bolov Mar 21 '18 at 11:00
  • Actually, I think searching for std::move being called is probably a good start. – Coder_Dan Mar 21 '18 at 13:46

1 Answers1

2

Simply look for them in your codebase:

grep -E '\(.*&&.*\)' | grep -v noexcept

You might need to improve this regexp in order to better filter matches. You can:

  • take advantage that a move constructor, as all constructors, has no return type (^\w*\W*\();
  • take advantage that a move constructor takes exactly one argument (replace .* by [^,]*);
  • filter only declarations or definitions looking for the final semi-colon.
YSC
  • 38,212
  • 9
  • 96
  • 149