This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]