mirror of
https://github.com/TinyCC/tinycc.git
synced 2025-11-16 12:34:45 +00:00
Relaxed the 'incompatible pointer type' warning a bit
Do not emit that warning when the source struct (recursively) contains destination struct as the first member. For example, in this case the warning would have been emitted before, and is not anymore:
struct base {
int a;
};
struct derived {
struct base base;
int b;
};
struct derived derived;
struct base *base = &derived;
I personally use that pattern in my code (in a bit more elaborate form) and so this change removes the warnings for those use cases, while still retaining it for everything else. Feel free to CC me on the mailing list if you have questions, suggestions or complaints.
This commit is contained in:
24
tccgen.c
24
tccgen.c
@@ -3591,7 +3591,8 @@ static void cast_error(CType *st, CType *dt)
|
||||
static void verify_assign_cast(CType *dt)
|
||||
{
|
||||
CType *st, *type1, *type2;
|
||||
int dbt, sbt, qualwarn, lvl;
|
||||
Sym *sym;
|
||||
int dbt, sbt, qualwarn, lvl, compat;
|
||||
|
||||
st = &vtop->type; /* source type */
|
||||
dbt = dt->t & VT_BTYPE;
|
||||
@@ -3645,10 +3646,31 @@ static void verify_assign_cast(CType *dt)
|
||||
base types, though, in particular for unsigned enums
|
||||
and signed int targets. */
|
||||
} else {
|
||||
compat = 0;
|
||||
/* Don't warn if the source struct (recursively) contains
|
||||
destination struct as the first member. */
|
||||
if (dbt == VT_STRUCT && sbt == VT_STRUCT
|
||||
&& !IS_UNION(type2->t)
|
||||
) {
|
||||
sym = type2->ref->next;
|
||||
while (sym != NULL && (sym->type.t & VT_BTYPE) == VT_STRUCT
|
||||
) {
|
||||
if (is_compatible_unqualified_types(type1, &sym->type)
|
||||
) {
|
||||
compat = 1;
|
||||
break;
|
||||
}
|
||||
if (IS_UNION(sym->type.t))
|
||||
break;
|
||||
sym = sym->type.ref->next;
|
||||
}
|
||||
}
|
||||
if( !compat ) {
|
||||
tcc_warning("assignment from incompatible pointer type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (qualwarn)
|
||||
tcc_warning_c(warn_discarded_qualifiers)("assignment discards qualifiers from pointer target type");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user