C++ Don'ts

Undefine Behaviour

return for [[noreturn]]

source

[[noreturn]] constexpr int DontDoThis() { return 42;}
constexpr auto Execute() { return DontDoThis();}
std::cout << "Execute " << Execute() << std::endl; // segmentation fault

Bad Practice

Disable Return Value Optimization (RVO or Named RVO)

source: Item 25: Effective Modern C++

Widget makeWidget()
{
   Widget w; 

   return std::move(w); // NRVO as it's named local variable
}
  • Do this instead

Last updated