aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-11-29 16:42:39 -0500
committerPatrick Palka <ppalka@redhat.com>2023-11-29 16:42:39 -0500
commit220fe41fd4085e91a49e62dd815628ec4883a4ea (patch)
tree1ff5000bf39cd5717ccdb59c507f4f399ecc6280 /gcc
parent72e212c0290b70a7a87fbec58444787f1b177847 (diff)
downloadgcc-220fe41fd4085e91a49e62dd815628ec4883a4ea.zip
gcc-220fe41fd4085e91a49e62dd815628ec4883a4ea.tar.gz
gcc-220fe41fd4085e91a49e62dd815628ec4883a4ea.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.cc2
-rw-r--r--gcc/cp/semantics.cc6
-rw-r--r--gcc/testsuite/g++.dg/warn/Wparentheses-33.C24
3 files changed, 27 insertions, 5 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 092e6fd..c18718b 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20279,7 +20279,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
build_x_modify_expr sets it and it must not be reset
here. */
if (warning_suppressed_p (t, OPT_Wparentheses))
- suppress_warning (r, OPT_Wparentheses);
+ suppress_warning (STRIP_REFERENCE_REF (r), OPT_Wparentheses);
RETURN (r);
}
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index d30a3f9..04b0540 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -871,8 +871,7 @@ is_assignment_op_expr_p (tree t)
void
maybe_warn_unparenthesized_assignment (tree t, tsubst_flags_t complain)
{
- if (REFERENCE_REF_P (t))
- t = TREE_OPERAND (t, 0);
+ t = STRIP_REFERENCE_REF (t);
if ((complain & tf_warning)
&& warn_parentheses
@@ -2176,8 +2175,7 @@ finish_parenthesized_expr (cp_expr expr)
{
/* This inhibits warnings in maybe_warn_unparenthesized_assignment
and c_common_truthvalue_conversion. */
- tree inner = REFERENCE_REF_P (expr) ? TREE_OPERAND (expr, 0) : *expr;
- suppress_warning (inner, OPT_Wparentheses);
+ suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
}
if (TREE_CODE (expr) == OFFSET_REF
diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-33.C b/gcc/testsuite/g++.dg/warn/Wparentheses-33.C
new file mode 100644
index 0000000..cc5038e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wparentheses-33.C
@@ -0,0 +1,24 @@
+// PR c++/112765
+
+struct A {
+ A& operator=(const A&);
+ operator bool() const;
+};
+
+template<class T>
+void f(A a1, A a2) {
+ if ((a2 = a1)) // { dg-bogus "parentheses" }
+ return;
+ bool b = (a2 = a1); // { dg-bogus "parentheses" }
+}
+
+template void f<int>(A, A);
+
+template<class T>
+void g(T a1, T a2) {
+ if ((a2 = a1)) // { dg-bogus "parentheses" }
+ return;
+ bool b = (a2 = a1); // { dg-bogus "parentheses" }
+}
+
+template void g<A>(A, A);