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

Reply via email to