On Thu, 9 May 2024, Patrick Palka wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk/14? For trunk as a follow-up I can implement the
mentionted representation change to use CALL_EXPR instead of
MODOP_EXPR for a non-dependent simple assignment expression that
resolved to an operator= overload.
FWIW, this is the WIP patch for that including the -Wparentheses
logic adjustments needed to avoid regressing
g++.dg/warn/Wparentheses-{32,33}.C
PR c++/114994
gcc/cp/ChangeLog:
* call.cc (build_new_op): Pass 'overload' to
cp_build_modify_expr.
* cp-tree.h (cp_build_modify_expr): New overload that
takes a tree* out-parameter.
* pt.cc (tsubst_expr) <case CALL_EXPR>: Propagate
OPT_Wparentheses warning suppression to the result.
* semantics.cc (is_assignment_op_expr_p): Also recognize
templated operator expressions represented as a CALL_EXPR
to operator=.
* typeck.cc (cp_build_modify_expr): Add 'overload'
out-parameter and pass it to build_new_op.
(build_x_modify_expr): Pass 'overload' to cp_build_modify_expr.
---
gcc/cp/call.cc | 2 +-
gcc/cp/cp-tree.h | 3 +++
gcc/cp/pt.cc | 2 ++
gcc/cp/semantics.cc | 11 +++++++++++
gcc/cp/typeck.cc | 18 ++++++++++++++----
5 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 7c4ecf08c4b..1cd4992330c 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -7473,7 +7473,7 @@ build_new_op (const op_location_t &loc, enum tree_code
code, int flags,
switch (code)
{
case MODIFY_EXPR:
- return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
+ return cp_build_modify_expr (loc, arg1, code2, arg2, overload, complain);
case INDIRECT_REF:
return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f82446331b3..505c04c6e52 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8264,6 +8264,9 @@ extern tree cp_build_c_cast
(location_t, tree, tree,
extern cp_expr build_x_modify_expr (location_t, tree,
enum tree_code, tree,
tree, tsubst_flags_t);
+extern tree cp_build_modify_expr (location_t, tree,
+ enum tree_code, tree,
+ tree *, tsubst_flags_t);
extern tree cp_build_modify_expr (location_t, tree,
enum tree_code, tree,
tsubst_flags_t);
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index f3d52acaaac..bc71e534cf8 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21091,6 +21091,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t
complain, tree in_decl)
if (warning_suppressed_p (t, OPT_Wpessimizing_move))
/* This also suppresses -Wredundant-move. */
suppress_warning (ret, OPT_Wpessimizing_move);
+ if (warning_suppressed_p (t, OPT_Wparentheses))
+ suppress_warning (STRIP_REFERENCE_REF (ret), OPT_Wparentheses);
}
RETURN (ret);
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index b8c2bf8771f..e81f2b50d80 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -863,6 +863,17 @@ is_assignment_op_expr_p (tree t)
return false;
tree fndecl = cp_get_callee_fndecl_nofold (call);
+ if (!fndecl
+ && processing_template_decl
+ && TREE_CODE (CALL_EXPR_FN (call)) == COMPONENT_REF)
+ {
+ /* Also recognize (non-dependent) templated operator expressions that
+ are represented as a direct call to operator=.
+ TODO: maybe move this handling to cp_get_fndecl_from_callee for
+ benefit of other callers. */