From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4521 invoked by alias); 4 Jun 2007 13:16:44 -0000 Received: (qmail 4474 invoked by uid 48); 4 Jun 2007 13:16:32 -0000 Date: Mon, 04 Jun 2007 13:16:00 -0000 Subject: [Bug c++/32205] New: "defined but not used" warning given or not depending on other errors X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "vz-gcc at zeitlins dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-06/txt/msg00194.txt.bz2 Consider the following code: % cat unused.cpp static int GetFoo() { return 17; } static int foo = GetFoo(); void bar() { } This compiles without warnings: % g++ -Wall -c unused.cpp % However if any error is introduced, like e.g. removing the closing brace of the bar() function, then we get both the (expected) error message and (less expected) warning: % g++ -Wall -c unused.cpp unused.cpp: In function 'void bar()': unused.cpp:6: error: expected `}' at end of input unused.cpp: At global scope: unused.cpp:3: warning: 'foo' defined but not used I don't know if the warning should or not be given (actually I'm glad to not have it in my code as my equivalent of GetFoo() has side effects) but it seems strange that the fact whether it's given or not depends on whether there are any other errors in the code. I realize this is not very important (hence the choice of severity) but I wanted to let you know about it in case this indicates some more serious problem with issuing this warning. Please feel free to ignore this bug report if it doesn't. Thanks! -- Summary: "defined but not used" warning given or not depending on other errors Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: trivial Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vz-gcc at zeitlins dot org GCC host triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32205