Hi, After recent changes, the member_name_cmp qsort comparator can indicate A < B < A (i.e. lacks anti-commutativity) for distinct TYPE_DECL nodes that have the same source location. If their order doesn't matter, the comparator should return 0.
Invoking qsort with improper comparator at best makes the output unpredictable (pedantically it invokes undefined behavior); this trips qsort checking I'm preparing to resend. (it also seems that this and the following comparators use less/greater pointer comparison, but unless those pointers point into the same array that invokes undefined behavior too, although benign in practice) Bootstrapped and regtested on x86-64, OK to apply? Thanks. Alexander * name-lookup.c (member_name_cmp): Return 0 if locations compare equal. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index d0aaf2b1d16..046cd109533 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1437,7 +1437,7 @@ member_name_cmp (const void *a_p, const void *b_p) 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; + goto compare_locations; /* If one of them is a TYPE_DECL, it loses. */ if (TREE_CODE (a) == TYPE_DECL) @@ -1456,7 +1456,10 @@ member_name_cmp (const void *a_p, const void *b_p) Order by source location. We should really prevent this happening. */ gcc_assert (errorcount); - return DECL_SOURCE_LOCATION (a) < DECL_SOURCE_LOCATION (b) ? -1 : +1; +compare_locations: + if (DECL_SOURCE_LOCATION (a) != DECL_SOURCE_LOCATION (b)) + return DECL_SOURCE_LOCATION (a) < DECL_SOURCE_LOCATION (b) ? -1 : +1; + return 0; } static struct {