This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C PATCH] field_decl_cmp


On Fri, 15 Sep 2017, Nathan Sidwell wrote:

> On 09/12/2017 12:48 PM, Joseph Myers wrote:
> 
> > I'd be concerned about the possibility of a qsort implementation that
> > calls the comparison function with two pointers to the same object (as far
> > as I can tell, it's valid for qsort to do that).  That is, I think you
> > need to check for the two DECLs being the same DECL, before asserting
> > their names are different.
> 
> I suppose we can drop the assert.  That does leave it returning +1 in the case
> you're concerned about, but I don't really see the need to tell such a stupid
> qsort that the things are unordered.

I don't know what such a qsort would do if such a case returned 1; my 
presumption is that all our comparison functions ought to return 0 when 
two objects are equal, even if that can only be if they are the same 
object.  It's OK with a return of 0 if x == y (or if DECL_NAME (x) == 
DECL_NAME (y), whichever you think appropriate).

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]