While working on 67557 I noticed that this pattern was checked in a few
places and decided to make it a macro, even though I didn't end up using
it in the fix for that bug.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 853122e015d3f20f80161bd820f616a34d3d5c16
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Oct 7 16:37:37 2015 -0400
* cp-tree.h (SIMPLE_TARGET_EXPR_P): New.
* init.c (get_nsdmi): Use it.
* typeck2.c (massage_init_elt): Use it.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 5acb065..f650c76 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4490,6 +4490,12 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
#define TARGET_EXPR_DIRECT_INIT_P(NODE) \
TREE_LANG_FLAG_2 (TARGET_EXPR_CHECK (NODE))
+/* True if NODE is a TARGET_EXPR that just expresses a copy of its INITIAL; if
+ the initializer has void type, it's doing something more complicated. */
+#define SIMPLE_TARGET_EXPR_P(NODE) \
+ (TREE_CODE (NODE) == TARGET_EXPR \
+ && !VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (NODE))))
+
/* True if EXPR expresses direct-initialization of a TYPE. */
#define DIRECT_INIT_EXPR_P(TYPE,EXPR) \
(TREE_CODE (EXPR) == TARGET_EXPR && TREE_LANG_FLAG_2 (EXPR) \
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 1ed8f6c..57a6406 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -588,8 +588,7 @@ get_nsdmi (tree member, bool in_ctor)
}
/* Strip redundant TARGET_EXPR so we don't need to remap it, and
so the aggregate init code below will see a CONSTRUCTOR. */
- if (init && TREE_CODE (init) == TARGET_EXPR
- && !VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (init))))
+ if (init && SIMPLE_TARGET_EXPR_P (init))
init = TARGET_EXPR_INITIAL (init);
init = break_out_target_exprs (init);
}
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 1d106c7..2c9143e 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1208,8 +1208,7 @@ massage_init_elt (tree type, tree init, tsubst_flags_t complain)
{
init = digest_init_r (type, init, true, LOOKUP_IMPLICIT, complain);
/* Strip a simple TARGET_EXPR when we know this is an initializer. */
- if (TREE_CODE (init) == TARGET_EXPR
- && !VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (init))))
+ if (SIMPLE_TARGET_EXPR_P (init))
init = TARGET_EXPR_INITIAL (init);
/* When we defer constant folding within a statement, we may want to
defer this folding as well. */