lint: make '_Static_assert' only available in C11 or C23 mode

This commit is contained in:
rillig 2023-08-03 18:48:42 +00:00
parent 4d0ce6b850
commit 0448d06008
7 changed files with 54 additions and 16 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1283 2023/08/03 13:13:05 rin Exp $
# $NetBSD: mi,v 1.1284 2023/08/03 18:48:42 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -7444,6 +7444,8 @@
./usr/tests/usr.bin/xlint/lint1/msg_351.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_352.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_353.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_354.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_355.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/op_colon.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/op_colon.exp tests-obsolete obsolete,atf
./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c tests-usr.bin-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
/* $NetBSD: c11.c,v 1.4 2023/07/28 22:05:44 rillig Exp $ */
/* $NetBSD: c11.c,v 1.5 2023/08/03 18:48:42 rillig Exp $ */
# 3 "c11.c"
/*
@ -43,9 +43,10 @@ three_times(void)
}
_Static_assert(1 > 0, "string");
/* XXX: requires C23 or later */
_Static_assert(1 > 0);
struct static_assert_tag {
_Static_assert(1 > 0, "string");
int member;
};
// C11 6.7.6.1p3

View File

@ -0,0 +1,14 @@
/* $NetBSD: msg_354.c,v 1.1 2023/08/03 18:48:42 rillig Exp $ */
# 3 "msg_354.c"
// Test for message 354: '_Static_assert' requires C11 or later [354]
//
// See also:
// c23.c
/* lint1-flags: -Sw -X 351 */
/* expect+1: error: '_Static_assert' requires C11 or later [354] */
_Static_assert(1 > 0, "message");
/* expect+1: error: '_Static_assert' without message requires C23 or later [355] */
_Static_assert(1 > 0);

View File

@ -0,0 +1,13 @@
/* $NetBSD: msg_355.c,v 1.1 2023/08/03 18:48:42 rillig Exp $ */
# 3 "msg_355.c"
// Test for message 355: '_Static_assert' without message requires C23 or later [355]
//
// See also:
// c23.c
/* lint1-extra-flags: -Ac11 -X 351 */
_Static_assert(1 > 0, "message");
/* expect+1: error: '_Static_assert' without message requires C23 or later [355] */
_Static_assert(1 > 0);

View File

@ -1,4 +1,4 @@
# $NetBSD: t_usage.sh,v 1.10 2023/07/02 23:40:23 rillig Exp $
# $NetBSD: t_usage.sh,v 1.11 2023/08/03 18:48:42 rillig Exp $
#
# Copyright (c) 2023 The NetBSD Foundation, Inc.
# All rights reserved.
@ -39,13 +39,13 @@ suppress_messages_body()
# The largest known message.
atf_check \
"$lint1" -X 353 code.c /dev/null
"$lint1" -X 355 code.c /dev/null
# Larger than the largest known message.
atf_check \
-s 'exit:1' \
-e "inline:lint1: invalid message ID '354'\n" \
"$lint1" -X 354 code.c /dev/null
-e "inline:lint1: invalid message ID '356'\n" \
"$lint1" -X 356 code.c /dev/null
# Whitespace is not allowed before a message ID.
atf_check \

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.469 2023/08/02 21:11:35 rillig Exp $ */
/* $NetBSD: cgram.y,v 1.470 2023/08/03 18:48:42 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
__RCSID("$NetBSD: cgram.y,v 1.469 2023/08/02 21:11:35 rillig Exp $");
__RCSID("$NetBSD: cgram.y,v 1.470 2023/08/03 18:48:42 rillig Exp $");
#endif
#include <limits.h>
@ -1695,9 +1695,15 @@ designator: /* C99 6.7.8 "Initialization" */
;
static_assert_declaration:
T_STATIC_ASSERT T_LPAREN
constant_expression T_COMMA T_STRING T_RPAREN T_SEMI /* C11 */
| T_STATIC_ASSERT T_LPAREN constant_expression T_RPAREN T_SEMI /* C23 */
T_STATIC_ASSERT T_LPAREN constant_expression T_COMMA T_STRING
T_RPAREN T_SEMI {
/* '_Static_assert' requires C11 or later */
c11ism(354);
}
| T_STATIC_ASSERT T_LPAREN constant_expression T_RPAREN T_SEMI {
/* '_Static_assert' without message requires C23 or later */
c23ism(355);
}
;
range:

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.215 2023/08/02 18:51:25 rillig Exp $ */
/* $NetBSD: err.c,v 1.216 2023/08/03 18:48:42 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
__RCSID("$NetBSD: err.c,v 1.215 2023/08/02 18:51:25 rillig Exp $");
__RCSID("$NetBSD: err.c,v 1.216 2023/08/03 18:48:42 rillig Exp $");
#endif
#include <limits.h>
@ -409,6 +409,8 @@ static const char *const msgs[] = {
"missing%s header declaration for '%s'", /* 351 */
"nested 'extern' declaration of '%s'", /* 352 */
"empty initializer braces require C23 or later", /* 353 */
"'_Static_assert' requires C11 or later", /* 354 */
"'_Static_assert' without message requires C23 or later", /* 355 */
};
static bool is_suppressed[sizeof(msgs) / sizeof(msgs[0])];