Don't produce type mismatch warnings if one side of ?: is "[qual] void *"

and the other side is "[qual] pointer".
This commit is contained in:
christos 2009-03-02 20:53:10 +00:00
parent 4bd0e7cebc
commit 7c8a9296cc
3 changed files with 35 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.44 2008/11/16 07:06:37 dholland Exp $ */ /* $NetBSD: decl.c,v 1.45 2009/03/02 20:53:10 christos Exp $ */
/* /*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: decl.c,v 1.44 2008/11/16 07:06:37 dholland Exp $"); __RCSID("$NetBSD: decl.c,v 1.45 2009/03/02 20:53:10 christos Exp $");
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -1994,6 +1994,31 @@ isredec(sym_t *dsym, int *dowarn)
return (0); return (0);
} }
static int
chkqual(type_t *tp1, type_t *tp2, int ignqual)
{
if (tp1->t_const != tp2->t_const && !ignqual && !tflag)
return 0;
if (tp1->t_volatile != tp2->t_volatile && !ignqual && !tflag)
return 0;
return 1;
}
int
eqptrtype(type_t *tp1, type_t *tp2, int ignqual)
{
if (tp1->t_tspec != VOID && tp2->t_tspec != VOID)
return 0;
if (!chkqual(tp1, tp2, ignqual))
return 0;
return 1;
}
/* /*
* Checks if two types are compatible. Returns 0 if not, otherwise 1. * Checks if two types are compatible. Returns 0 if not, otherwise 1.
* *
@ -2029,11 +2054,8 @@ eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *dowarn)
if (t != tp2->t_tspec) if (t != tp2->t_tspec)
return (0); return (0);
if (tp1->t_const != tp2->t_const && !ignqual && !tflag) if (!chkqual(tp1, tp2, ignqual))
return (0); return 0;
if (tp1->t_volatile != tp2->t_volatile && !ignqual && !tflag)
return (0);
if (t == STRUCT || t == UNION) if (t == STRUCT || t == UNION)
return (tp1->t_str == tp2->t_str); return (tp1->t_str == tp2->t_str);

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.24 2008/11/16 07:06:37 dholland Exp $ */ /* $NetBSD: externs1.h,v 1.25 2009/03/02 20:53:10 christos Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -166,6 +166,7 @@ extern sym_t *ename(sym_t *, int, int);
extern void decl1ext(sym_t *, int); extern void decl1ext(sym_t *, int);
extern void cpuinfo(sym_t *, sym_t *); extern void cpuinfo(sym_t *, sym_t *);
extern int isredec(sym_t *, int *); extern int isredec(sym_t *, int *);
extern int eqptrtype(type_t *, type_t *, int);
extern int eqtype(type_t *, type_t *, int, int, int *); extern int eqtype(type_t *, type_t *, int, int, int *);
extern void compltyp(sym_t *, sym_t *); extern void compltyp(sym_t *, sym_t *);
extern sym_t *decl1arg(sym_t *, int); extern sym_t *decl1arg(sym_t *, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.54 2008/11/16 07:06:37 dholland Exp $ */ /* $NetBSD: tree.c,v 1.55 2009/03/02 20:53:11 christos Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.54 2008/11/16 07:06:37 dholland Exp $"); __RCSID("$NetBSD: tree.c,v 1.55 2009/03/02 20:53:11 christos Exp $");
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -1105,6 +1105,8 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
} }
if (rt == PTR && lt == PTR) { if (rt == PTR && lt == PTR) {
if (eqptrtype(lstp, rstp, 1))
break;
if (!eqtype(lstp, rstp, 1, 0, NULL)) if (!eqtype(lstp, rstp, 1, 0, NULL))
illptrc(mp, ltp, rtp); illptrc(mp, ltp, rtp);
break; break;