This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
No warning on unused variable
- From: D Haley <djhaley at netspace dot net dot au>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 24 Oct 2006 15:33:03 +1000
- Subject: No warning on unused variable
Hello,
I came across this situation recently
Consider the following code
#include <sstream>
using std::stringstream;
int main()
{
int i;
stringstream ss;
}
I the compiled it with
gcc main.cpp -Wall -lstdc++
>main.cpp: In function 'int main()':
>main.cpp:7: warning: unused variable 'i'
Why did this not warn me about the unused stringstream?
Can wall only catch unused primitive types?
Is it because the constructor is called and therefore it is not unused?
It seems that -Wall should pick this up from the point of view of "i
declared it then did nothing, this is incorrect" (also i used no params
in the constructor), but it is concievable that declaring this object
might be sufficient for some action to be taken by the code, thus
rendering it incorrect for -Wall to report it.
Is this desirable behaviour by GCC or not?
Thankyou.