diff --git a/tests/usr.bin/xlint/lint1/msg_333.c b/tests/usr.bin/xlint/lint1/msg_333.c index 7a47dd348b14..ca82b108f81b 100644 --- a/tests/usr.bin/xlint/lint1/msg_333.c +++ b/tests/usr.bin/xlint/lint1/msg_333.c @@ -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"; diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c index 0727edc06cce..412a60bb6385 100644 --- a/usr.bin/xlint/lint1/func.c +++ b/usr.bin/xlint/lint1/func.c @@ -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 #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 @@ -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;