public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sss@li-snyder.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present
Date: Wed, 29 Nov 2023 15:51:53 +0000	[thread overview]
Message-ID: <bug-112765-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112765

            Bug ID: 112765
           Summary: [14 regression] -Wparentheses warning even when extra
                    parens are present
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sss@li-snyder.org
  Target Milestone: ---

hi -

With a recent checkout of gcc14 (20231129), on a x86_64-pc-linux-gnu host,
the following source gives a bogus -Wparentheses warning
with -Wall:

--------------------------------------------------------------
struct ptr
{
  ptr& operator= (ptr&& __u);
  explicit operator bool() const;
};

ptr getShare ();

template<class T>
class AnaToolHandle final
{
public:
  int getMode (ptr& sharedTool) const;
};

template<class T>
int AnaToolHandle<T>::getMode (ptr& sharedTool) const
{
  if ((sharedTool = getShare ()))
    return 0;

  return 1;
}

void initialize(AnaToolHandle<int>& jetCleaningTool)
{
  ptr sharedTool;
  jetCleaningTool.getMode (sharedTool);
}
--------------------------------------------------------------


$ g++ -c -Wall x.cc
x.cc: In instantiation of ‘int AnaToolHandle<T>::getMode(ptr&) const [with T =
int]’:
x.cc:28:27:   required from here
   28 |   jetCleaningTool.getMode (sharedTool);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
x.cc:19:31: warning: suggest parentheses around assignment used as truth value
[-Wparentheses]
   19 |   if ((sharedTool = getShare ()))
      |                               ^


It is true that there is an assignment used as a truth value, and in the
original code this was intentional, which the author signalled by adding
an extra pair of parentheses.  However, gcc emits the warning even though
the extra parentheses are there.  (Adding yet another pair of parentheses
around the condition does not silence the warning.)

This warning does not occcur with gcc 13.2.1 20230728.

             reply	other threads:[~2023-11-29 15:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29 15:51 sss@li-snyder.org [this message]
2023-11-29 15:55 ` [Bug c++/112765] " mpolacek at gcc dot gnu.org
2023-11-29 16:34 ` ppalka at gcc dot gnu.org
2023-11-29 21:42 ` cvs-commit at gcc dot gnu.org
2023-11-29 22:03 ` cvs-commit at gcc dot gnu.org
2023-11-29 22:04 ` ppalka at gcc dot gnu.org

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=bug-112765-4@http.gcc.gnu.org/bugzilla/ \
    --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).