By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Should this generate a warning?

P: n/a
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.

Jun 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
st*************@googlemail.com wrote:
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.
You can check any code you want against the compiler best known as the
most standard compliant around here:
http://www.comeaucomputing.com/tryitout/
Jun 19 '07 #2

P: n/a
On Tue, 19 Jun 2007 09:17:32 -0700 in comp.lang.c++,
st*************@googlemail.com wrote,
>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.
It is the compiler's prerogative to warn you or not warn you about
anything it might feel like (in addition to diagnostics required by the
standard.) Unused temporaries are ubiquitous, for example unused return
values from functions, and a compiler that warned you about every little
routine thing like that might not be very popular.
Jun 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.