Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

clang

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.)

like image 202
Dovahkiin Avatar asked Jan 22 '26 02:01

Dovahkiin


1 Answers

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.

like image 121
Peter Hall Avatar answered Jan 23 '26 16:01

Peter Hall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!