[PATCH] v3: C/C++: add fix-it hints for missing '&' and '*' (PR c++/87850)

David Malcolm dmalcolm@redhat.com
Tue Nov 20 22:05:00 GMT 2018


On Tue, 2018-11-20 at 02:46 +0000, Joseph Myers wrote:
> On Mon, 19 Nov 2018, David Malcolm wrote:
> 
> > +/* C implementation of same_type_p.
> > +   Returns true iff TYPE1 and TYPE2 are the same type, in the
> > usual
> > +   sense of `same'.  */
> > +
> > +bool
> > +same_type_p (tree type1, tree type2)
> > +{
> > +  return comptypes (type1, type2) == 1;
> > +}
> 
> I don't think "compatible" and "same" are the same concept.  Normally
> in C 
> you'd be concerned with compatibility; "same type" is only used for
> the 
> rule on duplicate typedefs, which uses
> comptypes_check_different_types.

The purpose here is to be able to offer fix-it hints for bogus code
that's missing an '&' or a '*' prefix, and have that code live in c-
common.c

Jason wanted to avoid a pointer-equality test for types by using
same_type_p to look through enums - but same_type_p is C++-specific.

Should I do:

(a) something like this for C:

/* C implementation of same_type_p.
   Returns true iff TYPE1 and TYPE2 are the same type, or are
   compatible enough to be permitted in C11 typedef redeclarations.  */

bool
same_type_p (tree type1, tree type2)
{
  bool different_types_p = false;
  int result = comptypes_check_different_types (type1, type2,
						&different_types_p);

  if (result == 1 && !different_types_p)
    return true;

  return false;   
}

(b) provide a same_type_p for C that e.g. simply does pointer equality,

(d) add a newly named function (e.g. "compatible_types_p", as C++ has a
comptypes, but it has a 3rd param), or

(d) fall back to simply doing pointer equality.


Thanks
Dave



More information about the Gcc-patches mailing list