public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present
@ 2023-11-29 15:51 sss@li-snyder.org
  2023-11-29 15:55 ` [Bug c++/112765] " mpolacek at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sss@li-snyder.org @ 2023-11-29 15:51 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/112765] [14 regression] -Wparentheses warning even when extra parens are present
  2023-11-29 15:51 [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present sss@li-snyder.org
@ 2023-11-29 15:55 ` mpolacek at gcc dot gnu.org
  2023-11-29 16:34 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-29 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
           Keywords|                            |diagnostic
   Target Milestone|---                         |14.0
   Last reconfirmed|                            |2023-11-29
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, started with r14-4111:

commit 6e92a6a2a72d3b7a5e1b29042d8a6a43fe1085aa
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Sep 18 14:47:52 2023 -0400

    c++: non-dependent assignment checking [PR63198, PR18474]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/112765] [14 regression] -Wparentheses warning even when extra parens are present
  2023-11-29 15:51 [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present sss@li-snyder.org
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-11-29 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/112765] [14 regression] -Wparentheses warning even when extra parens are present
  2023-11-29 15:51 [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present sss@li-snyder.org
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-29 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:220fe41fd4085e91a49e62dd815628ec4883a4ea

commit r14-5976-g220fe41fd4085e91a49e62dd815628ec4883a4ea
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Nov 29 16:42:39 2023 -0500

    c++: bogus -Wparentheses warning [PR112765]

    We need to consistently look through implicit INDIRECT_REF when
    setting/checking for -Wparentheses warning suppression.  In passing
    use the recently introduced STRIP_REFERENCE_REF helper some more.

            PR c++/112765

    gcc/cp/ChangeLog:

            * pt.cc (tsubst_expr) <case MODOP_EXPR>: Look through implicit
            INDIRECT_REF when propagating -Wparentheses warning suppression.
            * semantics.cc (maybe_warn_unparenthesized_assignment): Replace
            REFERENCE_REF_P handling with STRIP_REFERENCE_REF.
            (finish_parenthesized_expr): Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Wparentheses-33.C: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/112765] [14 regression] -Wparentheses warning even when extra parens are present
  2023-11-29 15:51 [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present sss@li-snyder.org
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-29 22:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:0b242afffdddc251eca96b37c59802aa66197be7

commit r14-5977-g0b242afffdddc251eca96b37c59802aa66197be7
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Nov 29 16:47:12 2023 -0500

    c++: fix testcase [PR112765]

            PR c++/112765

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Wparentheses-33.C: Compile with -Wparentheses.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/112765] [14 regression] -Wparentheses warning even when extra parens are present
  2023-11-29 15:51 [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present sss@li-snyder.org
                   ` (3 preceding siblings ...)
  2023-11-29 22:03 ` cvs-commit at gcc dot gnu.org
@ 2023-11-29 22:04 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-11-29 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Should be fixed, thanks for the bug report.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-29 22:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-29 15:51 [Bug c++/112765] New: [14 regression] -Wparentheses warning even when extra parens are present sss@li-snyder.org
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

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).