I ran into a code fragment similar to the following in a production
code base - although it was even worse since the class jimlad was a
class for doing locking similar to boost::mutex::scoped_lock.
class jimlad {
public:
jimlad( int a ) { std::cout << "CONSTRUCT JIMLAD" << std::endl; }
~jimlad() { std::cout << "DESTRUCT JIMLAD" << std::endl; }
};
int main(int argc, char* argv[])
{
jimlad(1); //** This line
std::cout << "MIDDLE" << std::endl;
return 0;
}
The output is
CONSTRUCT JIMLAD
DESTRUCT JIMLAD
MIDDLE
I know that the original author intended the marked line to read
"jimlad something(1)" and to produce the output
CONSTRUCT JIMLAD
MIDDLE
DESTRUCT JIMLAd
and I can see why the code is wrong. My question is should it produce
a warning? It doesn't on VC7.1 or VC8, but I don't have any other
compilers handy to try it with, or a copy of the standard.
Can anyone try it on another compiler or let me know why it doesn't
warn you? Unused temporary or something would seem right to me.