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 <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:654f6978cdc85a3970ff2c478d4df3e55cf4d3ab commit r13-23-g654f6978cdc85a3970ff2c478d4df3e55cf4d3ab Author: Zhao Wei Liew <zhaoweil...@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 <zhaoweil...@gmail.com>