public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kkylheku at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/36587] Feature: add warning for constructor call with discarded return.
Date: Fri, 11 Dec 2009 02:34:00 -0000	[thread overview]
Message-ID: <20091211023408.10800.qmail@sourceware.org> (raw)
In-Reply-To: <bug-36587-15518@http.gcc.gnu.org/bugzilla/>



------- Comment #4 from kkylheku at gmail dot com  2009-12-11 02:34 -------
(In reply to comment #3)
> This would have prevented bugs I've dealt with where critical sections where
> not protected:
> {
>   lock_guard (mutex);
>   // mutex NOT locked here!
> }
> But I'm not convinced that doing this is always a mistake.

Since we don't care about the object, we must care about the constructor side
effect. I seem to be under the impression that ISO C++ allows the construction
of temporary objects to be optimized away---even if there are side effects in
the constructor or destructor! Therefore, it's hard to see a valid use case for
this.

 Would the warning be
> suppressed by casting to void?
>   (void) TypeWithSideEffectsInCtor(x);

Not as implemented, I am afraid. The diagnostic is still produced that the
object is discarded. This is can be regarded as a flaw; something explicitly
requested by a cast should not be diagnosed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36587


  parent reply	other threads:[~2009-12-11  2:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-20 19:22 [Bug c++/36587] New: " kkylheku at gmail dot com
2008-06-20 19:24 ` [Bug c++/36587] " kkylheku at gmail dot com
2008-06-20 20:27 ` kkylheku at gmail dot com
2009-12-11  0:37 ` redi at gcc dot gnu dot org
2009-12-11  2:34 ` kkylheku at gmail dot com [this message]
2009-12-11 10:39 ` jwakely dot gcc at gmail dot com
2009-12-11 11:58 ` kkylheku at gmail dot com
     [not found] <bug-36587-4@http.gcc.gnu.org/bugzilla/>
2013-09-24 21:49 ` redi at gcc dot gnu.org
2013-09-24 21:52 ` redi at gcc dot gnu.org
2015-07-23 13:51 ` manu at gcc dot gnu.org
2015-07-24 18:47 ` kkylheku at gmail dot com
2015-07-24 21:21 ` redi at gcc dot gnu.org
2015-07-24 22:29 ` manu at gcc dot gnu.org
2024-03-16 23:32 ` pinskia at gcc dot gnu.org
2024-03-18  2:44 ` kkylheku at gmail dot com
2024-03-18  2:53 ` kkylheku at gmail dot com
2024-03-18  6:50 ` redi at gcc dot gnu.org
2024-03-18  7:20 ` redi at gcc dot gnu.org
2024-03-18 16:18 ` kkylheku at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091211023408.10800.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).