Why does Clang warn about unused pointers and unused primitives, but not unused objects?

In this piece of code ...

sf::Time obj;
sf::Time* ptr;
int i;
int* p2;

      

The first line gives no warning, the other three. Why?

(Btw, this is a whole method. Nothing is done with variables.)

+3


source to share


1 answer


Objects can have constructors and destructors. Thus, while you cannot use a valid variable, you can rely on code that runs in the constructor or destructor.



A good example of this is std::lock_guard

, which uses a destructor to unlock the mutex when the lock goes out of scope.

+6


source







All Articles