Menu

Object destroyed immediately warning

Fraser
2024-01-18
2024-01-19
  • Fraser

    Fraser - 2024-01-18

    I have some objects without names that are created and destroyed with one statement. This minimises the objects lifetime. CPPCheck tells me "Instance of 'xxx' object is destroyed immediately." as a style warning. I see this as good style.

     
  • Daniel Marjamäki

    there can be bugs from such mistakes when a name is forgotten for instance:

    void foo() {
         std::lock(m);
    }
    

    could you give us some idea about why it's a FP in your case?

     
  • Fraser

    Fraser - 2024-01-19

    My objects that are created and destroyed in one statement always do something required and it is often quite a lot. I've found it can be easier to debug when the debugger can use an identifier and there are more statements to put breakpoints on. Your example is probably an exceptional case and it given at C++ Core Guidelines somewhere.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.