Is there any way to generate a warning in VS2008 for unused using statements? I know there is the Edit->Intellisense->Organize Usings->Remove Unused Usings
, but it would be nice if this were a compile time warning.
The warning is made into an error by -pedantic-errors . Same as -Wimplicit-int and -Wimplicit-function-declaration . This warning is enabled by -Wall . -Wimplicit-fallthrough is the same as -Wimplicit-fallthrough=3 and -Wno-implicit-fallthrough is the same as -Wimplicit-fallthrough=0 .
Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don't interrupt the compilation process.
To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.
The compiler can suppress warnings that were introduced after a version you specify by using the /Wv compiler option.
We try to create warnings for situations where the code in question is almost certainly broken, misleading or useless. Furthermore, since many people compile with "warnings as errors" turned on, we have a high bar; it's bad to introduce a spurious or superfluous warning.
Imagine you were compiling with "warnings as errors" turned on by default. Imagine we implemented the feature you want. You start up a new project, and we generate for you:
using System;
using System.Text;
using System.Linq;
class Program
{
static void Main(string[] arguments)
{
}
}
and we immediately tell you that you have an error in your program because none of the "usings" are necessary! That is a very bad user experience. Those "usings" are put there by the IDE for your convenience, so that you don't have to define them yourself. Your proposed feature would turn that from a convenience into a nag.
No because it is not a compiler issue, so you cannot generate compiler warnings. Compiler warnings only get generated when a dead code spot is found, such as an empty catch statement. Or an unused variable. Basically anything that could cause runtime issues. Since using statements have nothing to do with runtime and are more style issues of a text file, they will not generate warnings.
But you can use a tool like reSharper to alert you of unused using statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With