Dovahkiin
Dovahkiin

Reputation: 1056

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

In this code snippet...

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

The first line doesn't produce a warning, but the other three do. How come?

(Btw, this is an entire method. Nothing is done with the variables.)

Upvotes: 3

Views: 101

Answers (1)

Peter Hall
Peter Hall

Reputation: 58745

Objects can have constructors and destructors. So, while you may not be using the actual variable, you may be relying on code that runs in the constructor or destructor.

A good example of this is std::lock_guard, which takes advantage of a destructor to unlock a mutex when the lock goes out of scope.

Upvotes: 6

Related Questions