Bug 16139 - Wrong warnings (unused variable) reported for the code provided when -Wall is used
Summary: Wrong warnings (unused variable) reported for the code provided when -Wall is...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-22 15:03 UTC by Karel Gardas
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karel Gardas 2004-06-22 15:04:01 UTC
Hello,

while developing MICO, I've found that gcc3.4.0 only reports some unused
variables, although the code contains much more. i.e. following code:

---code-----
#include <vector>
#include <string>

using namespace std;

void
foo()
{
    bool tcpip_initiator_used = false;
    string tcpip_initiator_options = "";
    bool tcpip_acceptor_used = false;
    string tcpip_acceptor_options = "";
    bool tls_initiator_used = false;
    string tls_initiator_options = "";
    bool tls_acceptor_used = false;
    string tls_acceptor_options = "";
    string tls_certs_initiator_options = "";
    string tls_certs_acceptor_options = "";
    vector<pair<string, string> > client_users;
    vector<pair<string, string> > server_users;
}

int
main(int argc, char* argv[])
{
  foo();
  return 0;
}

-----code-----

produces:

$ c++ -Wall -c w1.cc 
w1.cc: In function `void foo()':
w1.cc:9: warning: unused variable 'tcpip_initiator_used'
w1.cc:11: warning: unused variable 'tcpip_acceptor_used'
w1.cc:13: warning: unused variable 'tls_initiator_used'
w1.cc:15: warning: unused variable 'tls_acceptor_used'
$ 

Interesting is that it only reports bool variables as an unused. IMHO it should
report all variables in foo() function as unused.

Thanks,

Karel
Comment 1 Andrew Pinski 2004-06-22 15:30:13 UTC
Invalid as they are not unused as the construtor gets called which might have side effects sorry.
Comment 2 Wolfgang Bangerth 2004-06-22 17:24:26 UTC
Well, I wouldn't call it "invalid", just "infeasible". Note that all the 
variables you don't get warnings about have non-trivial constructors that 
have side effects. Sometimes, as in some patterns, a con/destructor call is 
the only interesting effect of a class, the variable is actually not 
used otherwise. To prevent warnings in these cases, the compiler can't] 
warn you in the cases you show. 
 
W. 
Comment 3 Karel Gardas 2004-06-22 18:16:02 UTC
OK, you have convience me enough. :-) Anyway, I have tested it also with Intel
C++ 8.0 and Comeau C++ 4.3.3 and both emits the same warnings, so everything is
ok...
Thanks,
Karel