GCC: "unused variable" warning not reported

GCC: "unused variable" warning not reported

Post by Mathieu Dezi » Thu, 31 May 2001 21:05:42



Hi all,

Even when I am using the option -Wall OR -Wunused, I am not warned
about unused variables (I deliberately introduce unused variables to
test the compiler ability to warn).
Any idea?

I am compiling C++ program with G++.

Thank you,
Mathieu Deziel

 
 
 

GCC: "unused variable" warning not reported

Post by Villy Kru » Thu, 31 May 2001 23:53:15


On 30 May 2001 05:05:42 -0700,

Quote:>Hi all,

>Even when I am using the option -Wall OR -Wunused, I am not warned
>about unused variables (I deliberately introduce unused variables to
>test the compiler ability to warn).
>Any idea?

Its ability to do so depend on the chosen optimization level.  The
information about unused variables is a side product of optimizing
the code.

Villy

 
 
 

GCC: "unused variable" warning not reported

Post by Charles Wilki » Fri, 01 Jun 2001 00:52:34


To get that, I use:

g++ -O2 -Wall -W binaryoutfile -o sourcefile.c

Charles



>Hi all,

>Even when I am using the option -Wall OR -Wunused, I am not warned
>about unused variables (I deliberately introduce unused variables to
>test the compiler ability to warn).
>Any idea?

>I am compiling C++ program with G++.

>Thank you,
>Mathieu Deziel

 
 
 

GCC: "unused variable" warning not reported

Post by Nate Eldredg » Fri, 01 Jun 2001 04:18:32



> Hi all,

> Even when I am using the option -Wall OR -Wunused, I am not warned
> about unused variables (I deliberately introduce unused variables to
> test the compiler ability to warn).
> Any idea?

> I am compiling C++ program with G++.

You should probably discuss this with the GCC developers.  Try

--

Nate Eldredge

 
 
 

GCC: "unused variable" warning not reported

Post by Mathieu Dezi » Sat, 02 Jun 2001 01:01:10


Quote:> > Even when I am using the option -Wall OR -Wunused, I am not warned
> > about unused variables (I deliberately introduce unused variables to
> > test the compiler ability to warn).

Ok, here was my problem: a tab at the end of a line in my makefile caused
the Makefile to be read incorrectly.  Thank you all for your help.

Quote:> > Its ability to do so depend on the chosen optimization level.
> > The information about unused variables is a side product of
> > optimizing the code.

Villy, I don't see how optimization would prevent some
warnings on the source code to be reported.  The "Unused variable" warning
relates to the source code itself, not to the compiled code (which,
with optimization turned on, might not reflect exactly the source code).
I haven't done any extensive tests, but changing the optimization level had
no impact on the warnings reported in my case.
Do you have some more details about it?  Am I missing something ?

Thank you, Mathieu.

 
 
 

GCC: "unused variable" warning not reported

Post by Shankar Unn » Sat, 02 Jun 2001 09:34:09



> Villy, I don't see how optimization would prevent some
> warnings on the source code to be reported.  The "Unused variable" warning
> relates to the source code itself, not to the compiled code (which,

But the *analysis* to determine whether something is unused is complex,
and is  usually a side-effect of the analysis required for optimization,
which is why you only get the desired warnings when optimization is
turned on.

Of course, you could argue that "-Wall" should turn on optimization, but
that's a bit of a stretch functionality-wise. Or maybe -Wall should turn
on the analysis for optimization, but in a "read-only" fashion that
doesn't actually change the generated code.  But that would be a major
structural change (read: major rewrite), so it's probably not practical.

Just accept it as a "hysterical" thing..
--
Shankar.

 
 
 

GCC: "unused variable" warning not reported

Post by Micah Cowa » Thu, 07 Jun 2001 08:41:06



> > > Even when I am using the option -Wall OR -Wunused, I am not warned
> > > about unused variables (I deliberately introduce unused variables to
> > > test the compiler ability to warn).

> Ok, here was my problem: a tab at the end of a line in my makefile caused
> the Makefile to be read incorrectly.  Thank you all for your help.

> > > Its ability to do so depend on the chosen optimization level.
> > > The information about unused variables is a side product of
> > > optimizing the code.

> Villy, I don't see how optimization would prevent some
> warnings on the source code to be reported.  The "Unused variable" warning
> relates to the source code itself, not to the compiled code (which,
> with optimization turned on, might not reflect exactly the source code).
> I haven't done any extensive tests, but changing the optimization level had
> no impact on the warnings reported in my case.
> Do you have some more details about it?  Am I missing something ?

I think that Villy is thinking of the "uninitialized variable"
warning, for which this is true.  man gcc(1).

Micah

 
 
 

1. PATCH: eisa reports "0 device" not "0 devices"

Since it gets 1 device right it wasnt hard to fix 8)

diff -u --new-file --recursive --exclude-from /usr/src/exclude linux-2.5.65-bk3/drivers/eisa/eisa-bus.c linux-2.5.65-ac3/drivers/eisa/eisa-bus.c
--- linux-2.5.65-bk3/drivers/eisa/eisa-bus.c    2003-03-22 19:33:35.000000000 +0000

                        eisa_register_device (root, str, i);
                 }
         }
-        printk (KERN_INFO "EISA: Detected %d card%s.\n", c, c < 2 ? "" : "s");
+        printk (KERN_INFO "EISA: Detected %d card%s.\n", c, c == 1 ? "" : "s");

        return 0;
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. ISPs for Linux: Does anybody have any preferences?

3. GETSERVBYNAME()????????????????????"""""""""""""

4. X motif library where ?

5. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

6. Debian, Mandrake, SUSE, or Yellow Dog on a G3 Beige?

7. GCC: "makefile" not "Makefile"?

8. Sporadic serial port problems (mouse and modem)

9. "dfspace" reports correct information, but "df -v" does not.

10. Type "(", ")" and "{", "}" in X...

11. WARNING: "snd" is usurping "snd"'s cdevsw[]

12. apache variable "SSL=on" or "SSL=yes" ??