On 9/23/19 12:06 PM, Marek Polacek wrote:
On Mon, Sep 23, 2019 at 10:17:00AM -0400, Jason Merrill wrote:
On 9/22/19 3:23 PM, Marek Polacek wrote:
+ /* Informally, two types are similar if, ignoring top-level cv-qualification:
+ * they are the same type; or
+ * they are both pointers, and the pointed-to types are similar; or
+ * they are both pointers to member of the same class, and the types of
+ the pointed-to members are similar; or
+ * they are both arrays of the same size or both arrays of unknown bound,
+ and the array element types are similar. */
Yes.
+ if ((TREE_CODE (type1) == POINTER_TYPE && TREE_CODE (type2) == POINTER_TYPE)
+ || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
+ || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
+ {
+ int result = comp_cv_qual_signature (TREE_TYPE (type1),
+ TREE_TYPE (type2));
Using comp_cv_qual_signature means that we only return true if one
cv-qualification signature is a subset of the other, but the definition of
'similar' is such that we should completely ignore cv-quals. int const **
and int *const* are similar even though neither can convert to the other.
Ah, true, what I actually want is comp_ptr_ttypes_const. I didn't notice
because as you say, the conversion would fail with "discarding qualifiers".
But similar_type_p shouldn't give the wrong answer.
The handling of arrays will come in P0388R4.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
OK.
Jason