I am using g++ 4.3.0 to compile this example :
#include
int main()
{
std::vector< int > a;
int b;
}
If I compile
In theory, the default constructor for std::vector
could have arbitrary side effects, so the compiler cannot figure out whether removing the definition of a
would change the semantics of the program. You only get those warning for built-in types.
A better example is a lock:
{
lock a;
// ...
// do critical stuff
// a is never used here
// ...
// lock is automatically released by a's destructor (RAII)
}
Even though a
is never used after its definition, removing the first line would be wrong.