summaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-10-04 17:14:18 -0400
committerJason Merrill <jason@gcc.gnu.org>2016-10-04 17:14:18 -0400
commit2db613e5d3a2698fcd32460ad23b0c1b8ae31c7a (patch)
tree1a5e32cc80f2acb985b965737519edc6c20b1820 /gcc/cp/constexpr.c
parent76b294d48d6c375b76f1695ea56c960d5473439b (diff)
downloadgcc-2db613e5d3a2698fcd32460ad23b0c1b8ae31c7a.tar.gz
PR c++/77775 - misoptimization of PMF comparison
* constexpr.c (cxx_eval_component_reference): Use name matching for PMFs. From-SVN: r240757
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 2db13d2e187..4acbb2600b4 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2315,9 +2315,13 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
}
if (*non_constant_p)
return t;
+ bool pmf = TYPE_PTRMEMFUNC_P (TREE_TYPE (whole));
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (whole), i, field, value)
{
- if (field == part)
+ /* Use name match for PMF fields, as a variant will have a
+ different FIELD_DECL with a different type. */
+ if (pmf ? DECL_NAME (field) == DECL_NAME (part)
+ : field == part)
{
if (value)
return value;
@@ -2342,6 +2346,8 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
if (is_really_empty_class (TREE_TYPE (t)))
return build_constructor (TREE_TYPE (t), NULL);
+ gcc_assert (DECL_CONTEXT (part) == TYPE_MAIN_VARIANT (TREE_TYPE (whole)));
+
if (CONSTRUCTOR_NO_IMPLICIT_ZERO (whole))
{
/* 'whole' is part of the aggregate initializer we're currently