From 12f713131ef7ffc26cbff4c380e43109fe7afcef Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 21 Sep 2017 02:51:40 +0000 Subject: [PATCH] [C++ PATCH] class member ordering https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01426.html * name-lookup.c (member_name_cmp): Use DECL_UID for final ordering. From-SVN: r253048 --- gcc/cp/ChangeLog | 5 ++++ gcc/cp/name-lookup.c | 55 ++++++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b4edd80419e..b8d3f04f70f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-09-20 Nathan Sidwell + + * name-lookup.c (member_name_cmp): Use DECL_UID for final + ordering. + 2017-09-20 Jakub Jelinek P0409R2 - allow lambda capture [=, this] diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index d0aaf2b1d16..a3a124b9ce2 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1434,29 +1434,38 @@ member_name_cmp (const void *a_p, const void *b_p) b = OVL_FUNCTION (b); /* We're in STAT_HACK or USING_DECL territory (or possibly error-land). */ - if (TREE_CODE (a) == TREE_CODE (b)) - /* We can get two TYPE_DECLs or two USING_DECLs. Place in source - order. */ - return DECL_SOURCE_LOCATION (a) < DECL_SOURCE_LOCATION (b) ? -1 : +1; - - /* If one of them is a TYPE_DECL, it loses. */ - if (TREE_CODE (a) == TYPE_DECL) - return +1; - else if (TREE_CODE (b) == TYPE_DECL) - return -1; - - /* If one of them is a USING_DECL, it loses. */ - if (TREE_CODE (a) == USING_DECL) - return +1; - else if (TREE_CODE (b) == USING_DECL) - return -1; - - /* There are no other cases, as duplicate detection should have - kicked in earlier. However, some erroneous cases get though. - Order by source location. We should really prevent this - happening. */ - gcc_assert (errorcount); - return DECL_SOURCE_LOCATION (a) < DECL_SOURCE_LOCATION (b) ? -1 : +1; + if (TREE_CODE (a) != TREE_CODE (b)) + { + /* If one of them is a TYPE_DECL, it loses. */ + if (TREE_CODE (a) == TYPE_DECL) + return +1; + else if (TREE_CODE (b) == TYPE_DECL) + return -1; + + /* If one of them is a USING_DECL, it loses. */ + if (TREE_CODE (a) == USING_DECL) + return +1; + else if (TREE_CODE (b) == USING_DECL) + return -1; + + /* There are no other cases with different kinds of decls, as + duplicate detection should have kicked in earlier. However, + some erroneous cases get though. */ + gcc_assert (errorcount); + } + + /* Using source location would be the best thing here, but we can + get identically-located decls in the following circumstances: + + 1) duplicate artificial type-decls for the same type. + + 2) pack expansions of using-decls. + + We should not be doing #1, but in either case it doesn't matter + how we order these. Use UID as a proxy for source ordering, so + that identically-located decls still have a well-defined stable + ordering. */ + return DECL_UID (a) < DECL_UID (b) ? -1 : +1; } static struct { -- 2.30.2