On Thu, Sep 19, 2019 at 3:15 PM Alexander Monakov <amona...@ispras.ru> wrote:
>
> On Thu, 19 Sep 2019, Richard Biener wrote:
>
> > > Good point, there's a tested patch.
> >
> > OK.
>
> Hold on, is the new comparator really correct?
>
>
> @@ -3384,20 +3372,11 @@ sort_congruence_classes_by_decl_uid (const void *a, 
> const void *b)
>  static int
>  sort_congruence_class_groups_by_decl_uid (const void *a, const void *b)
>  {
> -  const congruence_class_group *g1
> -    = *(const congruence_class_group * const *)a;
> -  const congruence_class_group *g2
> -    = *(const congruence_class_group * const *)b;
> -
> -  int uid1 = DECL_UID (g1->classes[0]->members[0]->decl);
> -  int uid2 = DECL_UID (g2->classes[0]->members[0]->decl);
> -
> -  if (uid1 < uid2)
> -    return -1;
> -  else if (uid1 > uid2)
> -    return 1;
> -  else
> -    return 0;
> +  const std::pair<congruence_class_group *, int> *g1
> +    = *(const std::pair<congruence_class_group *, int> *const *) a;
> +  const std::pair<congruence_class_group *, int> *g2
> +    = *(const std::pair<congruence_class_group *, int> *const *) b;
> +  return g1->second - g2->second;
>  }
>
>
> AFAICT the vec holds pairs, not pointers to pairs, so why does the comparator
> cast to a pointer-to-pointer-to-pair? Shouldn't it read
>
>   const std::pair<congruence_class_group *, int> *g1
>     = (const std::pair<congruence_class_group *, int> *) a;

Indeed.  We need static type correctness for the comparator :/

Richard.

> Thanks.
> Alexander

Reply via email to