should help you out Note that the question has changed since the other answers were written. Likely the reason g++ doesn't warn in the current form is because mst is a reference, and constructing and destructing a reference has no side effects. It's true that here the reference is extending the lifetime of a temporary, which has effects in its constructor and destructor, but apparently g++ doesn't realise that makes a difference.
"error: 'xxx' undeclared" _and_ "error: unused variable 'xxx'" at the same time, in the same file
Any of those help You're using a for-in loop over an array, without using the enumerable keys (indices). You should use Array#forEach instead, and since it accepts a callback, you can just omit any arguments: