A hat type is a form of smart pointer, so each hat type has a destructor, which releases ownership of the pointed-to object. While spObject
is not referenced by name in your source code, the object is referenced by the compiler-generated call to the destructor at the end of the function.
When the compiler checks for unreferenced local variables, it finds this reference and does not issue the warning. An ordinary (non-parameter) local variable must have a name, and it would be problematic if the compiler issued "unreferenced local variable" warnings for such local variables that exist solely to be destroyed (e.g., RAII types like lock_guard
). Warnings C4101 and C4189 are issued for unreferenced non-parameter local variables. (Could the compiler treat parameters differently? Possibly. But it doesn't.)
Observe that C4100 is not issued for any parameter of a type that has a destructor:
struct A { };
struct B { ~B() { } };
void f(A a) { } // C4100 is issued for 'a'
void f(B b) { } // C4100 is not issued for 'b'