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

2022-02-15 Thread Zhao Wei Liew via Gcc-patches
On Wed Feb 16, 2022 at 4:06 AM +08, Jason Merrill wrote: > > Ah, I see. I found it a bit odd that gcc-commit-mklog auto-generated a > > subject with "c:", > > but I just went with it as I didn't know any better. Unfortunately, I > > can't change it now on the current thread. > > That came from th

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

2022-02-15 Thread Jason Merrill via Gcc-patches
On 2/15/22 11:30, Zhao Wei Liew wrote: On Tue, 15 Feb 2022 at 21:05, Jason Merrill > wrote: > >> > >> I agree. However, I can't seem to call extract_call_expr directly > >> because it calls gcc_assert > >> to assert that the resulting expression is a CALL_EXPR or AGG

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

2022-02-15 Thread Zhao Wei Liew via Gcc-patches
On Wed, 16 Feb 2022 at 00:30, Zhao Wei Liew wrote: > On Tue, 15 Feb 2022 at 21:05, Jason Merrill wrote: > > >> > > >> I agree. However, I can't seem to call extract_call_expr directly > > >> because it calls gcc_assert > > >> to assert that the resulting expression is a CALL_EXPR or > AGGR_INIT_

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

2022-02-15 Thread Zhao Wei Liew via Gcc-patches
On Tue, 15 Feb 2022 at 21:05, Jason Merrill wrote: > >> > >> I agree. However, I can't seem to call extract_call_expr directly > >> because it calls gcc_assert > >> to assert that the resulting expression is a CALL_EXPR or AGGR_INIT_EXPR. > >> Instead, I've extracted the non-assert-related code in

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

2022-02-15 Thread Jason Merrill via Gcc-patches
On 2/15/22 07:48, Jason Merrill wrote: On 2/15/22 05:06, Zhao Wei Liew wrote: On Tue, 15 Feb 2022 at 13:13, Jason Merrill wrote: On 2/14/22 21:30, Zhao Wei Liew wrote: On 14/02/2022, Jason Merrill wrote: +/* Returns true if EXPR is a reference to an implicit +   call to operator=(). */ +s

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

2022-02-15 Thread Jason Merrill via Gcc-patches
On 2/15/22 05:06, Zhao Wei Liew wrote: On Tue, 15 Feb 2022 at 13:13, Jason Merrill wrote: On 2/14/22 21:30, Zhao Wei Liew wrote: On 14/02/2022, Jason Merrill wrote: +/* Returns true if EXPR is a reference to an implicit + call to operator=(). */ +static bool +is_assignment_overload_ref_p

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

2022-02-15 Thread Zhao Wei Liew via Gcc-patches
On Tue, 15 Feb 2022 at 13:13, Jason Merrill wrote: > > On 2/14/22 21:30, Zhao Wei Liew wrote: > > On 14/02/2022, Jason Merrill wrote: > >>> > >>> +/* Returns true if EXPR is a reference to an implicit > >>> + call to operator=(). */ > >>> +static bool > >>> +is_assignment_overload_ref_p (tree e

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

2022-02-14 Thread Jason Merrill via Gcc-patches
On 2/14/22 21:30, Zhao Wei Liew wrote: On 14/02/2022, Jason Merrill wrote: +/* Returns true if EXPR is a reference to an implicit + call to operator=(). */ +static bool +is_assignment_overload_ref_p (tree expr) +{ + if (expr == NULL_TREE || !REFERENCE_REF_P (expr)) +return false; This

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

2022-02-14 Thread Zhao Wei Liew via Gcc-patches
On 14/02/2022, Jason Merrill wrote: >> >> +/* Returns true if EXPR is a reference to an implicit >> + call to operator=(). */ >> +static bool >> +is_assignment_overload_ref_p (tree expr) >> +{ >> + if (expr == NULL_TREE || !REFERENCE_REF_P (expr)) >> +return false; > > This will only warn a

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

2022-02-14 Thread Jason Merrill via Gcc-patches
On 2/12/22 01:59, Zhao Wei Liew wrote: On Fri, 11 Feb 2022 at 20:47, Jason Merrill wrote: On the other hand, for empty classes, it seems that a COMPOUND_EXPR is built in build_over_call under the is_really_empty_class guard (line 9791). I don't understand the tree structure that I should ident

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

2022-02-11 Thread Zhao Wei Liew via Gcc-patches
On Fri, 11 Feb 2022 at 20:47, Jason Merrill wrote: > > > > On the other hand, for empty classes, it seems that a COMPOUND_EXPR > > is built in build_over_call under the is_really_empty_class guard (line > > 9791). > > I don't understand the tree structure that I should identify though. > > Could

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

2022-02-11 Thread Jason Merrill via Gcc-patches
On 2/10/22 23:01, Zhao Wei Liew wrote: On Fri, 11 Feb 2022 at 00:14, Jason Merrill wrote: On 2/9/22 21:18, Zhao Wei Liew via Gcc-patches wrote: Hi! I wrote a patch for PR 25689, but I feel like it may not be the ideal fix. Furthermore, there are some standing issues with the patch for which

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

2022-02-10 Thread Zhao Wei Liew via Gcc-patches
On Fri, 11 Feb 2022 at 00:14, Jason Merrill wrote: > > On 2/9/22 21:18, Zhao Wei Liew via Gcc-patches wrote: > > Hi! > > > > I wrote a patch for PR 25689, but I feel like it may not be the ideal > > fix. Furthermore, there are some standing issues with the patch for > > which I would like tips on

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

2022-02-10 Thread Jason Merrill via Gcc-patches
On 2/9/22 21:18, Zhao Wei Liew via Gcc-patches wrote: Hi! I wrote a patch for PR 25689, but I feel like it may not be the ideal fix. Furthermore, there are some standing issues with the patch for which I would like tips on how to fix them. Specifically, there are 2 issues: 1. GCC warns about if

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

2022-02-09 Thread Zhao Wei Liew via Gcc-patches
Hi! I wrote a patch for PR 25689, but I feel like it may not be the ideal fix. Furthermore, there are some standing issues with the patch for which I would like tips on how to fix them. Specifically, there are 2 issues: 1. GCC warns about if (a.operator=(0)). That said, this may not be a major is