public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25689] missed diagnostic about assignment used as truth value.
       [not found] <bug-25689-4@http.gcc.gnu.org/bugzilla/>
@ 2021-08-10  0:44 ` pinskia at gcc dot gnu.org
  2022-02-09 17:24 ` zhaoweiliew at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-10  0:44 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2014-10-12 00:00:00         |2021-8-9
           Severity|minor                       |enhancement

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

* [Bug c++/25689] missed diagnostic about assignment used as truth value.
       [not found] <bug-25689-4@http.gcc.gnu.org/bugzilla/>
  2021-08-10  0:44 ` [Bug c++/25689] missed diagnostic about assignment used as truth value pinskia at gcc dot gnu.org
@ 2022-02-09 17:24 ` zhaoweiliew at gmail dot com
  2022-04-29  2:59 ` cvs-commit at gcc dot gnu.org
  2022-07-22 13:54 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: zhaoweiliew at gmail dot com @ 2022-02-09 17:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Zhao Wei Liew <zhaoweiliew at gmail dot com> ---
Created attachment 52395
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52395&action=edit
Test patch (seeking feedback)

Hi! I wrote a small patch to fix this issue, but I think that it has much room
for improvement, though I'm not very sure how. Could anyone take a look and
give me feedback on how I could improve the patch?

Here's an example code snippet. I've commented the expected and actual
diagnostic results beside the lines of code.

struct A {
  A& operator=(int);
  operator bool();
};

void f(A a, A b)
{
  if (a = 0); // GCC warns after patch (correct)
  if (a.operator=(0)) {} // GCC warns after patch (incorrect, but doesn't sound
like a major issue)
  if (a = b) {} // GCC does not warn before & after patch (incorrect)
}

Specifically, there are 2 issues:
1. GCC warns for `if (a.operator=(0))`
2. GCC does not warn for `if (a = b)` where the default copy/move assignment
operator is used.

Thanks!

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

* [Bug c++/25689] missed diagnostic about assignment used as truth value.
       [not found] <bug-25689-4@http.gcc.gnu.org/bugzilla/>
  2021-08-10  0:44 ` [Bug c++/25689] missed diagnostic about assignment used as truth value pinskia at gcc dot gnu.org
  2022-02-09 17:24 ` zhaoweiliew at gmail dot com
@ 2022-04-29  2:59 ` cvs-commit at gcc dot gnu.org
  2022-07-22 13:54 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-29  2:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:654f6978cdc85a3970ff2c478d4df3e55cf4d3ab

commit r13-23-g654f6978cdc85a3970ff2c478d4df3e55cf4d3ab
Author: Zhao Wei Liew <zhaoweiliew@gmail.com>
Date:   Tue Feb 15 17:44:29 2022 +0800

    c++: Add diagnostic when operator= is used as truth cond [PR25689]

    When compiling the following code with g++ -Wparentheses, GCC does not
    warn on the if statement. For example, there is no warning for this code:

    struct A {
            A& operator=(int);
            operator bool();
    };

    void f(A a) {
            if (a = 0); // no warning
    }

    This is because a = 0 is a call to operator=, which GCC does not handle.

    This patch fixes this issue by handling calls to operator= when deciding
    to warn.

    Bootstrapped and regression tested on x86_64-pc-linux-gnu.

            PR c++/25689

    gcc/cp/ChangeLog:

            * call.cc (extract_call_expr): Return a NULL_TREE on failure
            instead of asserting.
            (build_new_method_call): Suppress -Wparentheses diagnostic for
            MODIFY_EXPR.
            * semantics.cc (is_assignment_op_expr_p): Add function to check
            if an expression is a call to an op= operator expression.
            (maybe_convert_cond): Handle the case of a op= operator expression
            for the -Wparentheses diagnostic.

    gcc/testsuite/ChangeLog:

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

    Signed-off-by: Zhao Wei Liew <zhaoweiliew@gmail.com>

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

* [Bug c++/25689] missed diagnostic about assignment used as truth value.
       [not found] <bug-25689-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-04-29  2:59 ` cvs-commit at gcc dot gnu.org
@ 2022-07-22 13:54 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-07-22 13:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.0
         Resolution|---                         |FIXED

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13 I think?

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

* [Bug c++/25689] missed diagnostic about assignment used as truth value.
  2006-01-06  9:45 [Bug c++/25689] New: " pluto at agmk dot net
@ 2006-01-06 12:32 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-06 12:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-01-06 12:32 -------
Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2006-01-06 12:32:23
               date|                            |


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



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

end of thread, other threads:[~2022-07-22 13:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-25689-4@http.gcc.gnu.org/bugzilla/>
2021-08-10  0:44 ` [Bug c++/25689] missed diagnostic about assignment used as truth value pinskia at gcc dot gnu.org
2022-02-09 17:24 ` zhaoweiliew at gmail dot com
2022-04-29  2:59 ` cvs-commit at gcc dot gnu.org
2022-07-22 13:54 ` ppalka at gcc dot gnu.org
2006-01-06  9:45 [Bug c++/25689] New: " pluto at agmk dot net
2006-01-06 12:32 ` [Bug c++/25689] " pinskia at gcc dot gnu dot 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).