lint: fix type name in diagnostic for enum as controlling expression
Previously, the type was reported as 'int' instead of 'enum'. Continue to only report the type simple for pointer types, as the exact pointer type is irrelevant to this message.
This commit is contained in:
parent
1998cd1304
commit
0510ee8e2a
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msg_333.c,v 1.5 2022/06/17 18:54:53 rillig Exp $ */
|
||||
/* $NetBSD: msg_333.c,v 1.6 2023/05/11 08:01:36 rillig Exp $ */
|
||||
# 3 "msg_333.c"
|
||||
|
||||
// Test for message: controlling expression must be bool, not '%s' [333]
|
||||
|
@ -9,6 +9,14 @@
|
|||
|
||||
typedef _Bool bool;
|
||||
|
||||
static enum tagged_color {
|
||||
tagged_red,
|
||||
} e1;
|
||||
typedef enum {
|
||||
typedef_red,
|
||||
} typedef_color;
|
||||
static typedef_color e2;
|
||||
|
||||
const char *
|
||||
example(bool b, int i, const char *p)
|
||||
{
|
||||
|
@ -20,6 +28,14 @@ example(bool b, int i, const char *p)
|
|||
if (i)
|
||||
return "int";
|
||||
|
||||
/* expect+1: error: controlling expression must be bool, not 'enum tagged_color' [333] */
|
||||
if (e1)
|
||||
return "tagged enum";
|
||||
|
||||
/* expect+1: error: controlling expression must be bool, not 'enum typedef typedef_color' [333] */
|
||||
if (e2)
|
||||
return "typedef enum";
|
||||
|
||||
/* expect+1: error: controlling expression must be bool, not 'pointer' [333] */
|
||||
if (p)
|
||||
return "pointer";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $ */
|
||||
/* $NetBSD: func.c,v 1.154 2023/05/11 08:01:36 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $");
|
||||
__RCSID("$NetBSD: func.c,v 1.154 2023/05/11 08:01:36 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -623,7 +623,8 @@ check_controlling_expression(tnode_t *tn)
|
|||
|
||||
if (tn != NULL && Tflag && !is_typeok_bool_compares_with_zero(tn)) {
|
||||
/* controlling expression must be bool, not '%s' */
|
||||
error(333, tspec_name(tn->tn_type->t_tspec));
|
||||
error(333, tn->tn_type->t_is_enum ? type_name(tn->tn_type)
|
||||
: tspec_name(tn->tn_type->t_tspec));
|
||||
}
|
||||
|
||||
return tn;
|
||||
|
|
Loading…
Reference in New Issue