lint: reject _Noreturn if it occurs in invalid places
C11 introduced _Noreturn as a function-specifier, not as a type attribute. The latter may occur in more places.
This commit is contained in:
parent
5e96f60f79
commit
bc10e9be9d
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: c11.c,v 1.1 2023/07/12 18:13:39 rillig Exp $ */
|
||||
/* $NetBSD: c11.c,v 1.2 2023/07/12 18:26:04 rillig Exp $ */
|
||||
# 3 "c11.c"
|
||||
|
||||
/*
|
||||
|
@ -11,9 +11,6 @@
|
|||
_Noreturn void exit(int);
|
||||
void _Noreturn exit(int);
|
||||
|
||||
/* XXX: Syntactically invalid, yet lint accepts it. */
|
||||
void _Noreturn exit(int) _Noreturn;
|
||||
|
||||
_Noreturn void
|
||||
noreturn_before_type(void)
|
||||
{
|
||||
|
@ -44,3 +41,10 @@ three_times(void)
|
|||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* The '_Noreturn' must not appear after the declarator. */
|
||||
void _Noreturn exit(int) _Noreturn;
|
||||
/* expect-1: error: formal parameter #1 lacks name [59] */
|
||||
/* expect-2: warning: empty declaration [2] */
|
||||
/* expect+2: error: syntax error '' [249] */
|
||||
/* expect+1: error: cannot recover from previous errors [224] */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
%{
|
||||
/* $NetBSD: cgram.y,v 1.456 2023/07/12 16:07:35 rillig Exp $ */
|
||||
/* $NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 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.456 2023/07/12 16:07:35 rillig Exp $");
|
||||
__RCSID("$NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -132,7 +132,7 @@ is_either(const char *s, const char *a, const char *b)
|
|||
|
||||
%}
|
||||
|
||||
%expect 132
|
||||
%expect 104
|
||||
|
||||
%union {
|
||||
val_t *y_val;
|
||||
|
@ -223,7 +223,6 @@ is_either(const char *s, const char *a, const char *b)
|
|||
%token T_REAL
|
||||
%token T_IMAG
|
||||
%token T_GENERIC
|
||||
%token T_NORETURN
|
||||
|
||||
/* storage classes (extern, static, auto, register and typedef) */
|
||||
%token <y_scl> T_SCLASS
|
||||
|
@ -932,7 +931,6 @@ type_attribute: /* See C11 6.7 declaration-specifiers */
|
|||
| T_PACKED {
|
||||
dcs_add_packed();
|
||||
}
|
||||
| T_NORETURN
|
||||
;
|
||||
|
||||
begin_type:
|
||||
|
@ -1969,7 +1967,7 @@ for_exprs: /* see C99 6.8.5 */
|
|||
c99ism(325);
|
||||
stmt_for_exprs(NULL, $6, $8);
|
||||
clear_warning_flags();
|
||||
}
|
||||
}
|
||||
| for_start
|
||||
expression_opt T_SEMI
|
||||
expression_opt T_SEMI
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: debug.c,v 1.50 2023/07/12 16:07:35 rillig Exp $ */
|
||||
/* $NetBSD: debug.c,v 1.51 2023/07/12 18:26:04 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2021 The NetBSD Foundation, Inc.
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: debug.c,v 1.50 2023/07/12 16:07:35 rillig Exp $");
|
||||
__RCSID("$NetBSD: debug.c,v 1.51 2023/07/12 18:26:04 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -320,6 +320,7 @@ function_specifier_name(function_specifier spec)
|
|||
{
|
||||
static const char *const name[] = {
|
||||
"inline",
|
||||
"_Noreturn",
|
||||
};
|
||||
|
||||
return name[spec];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lex.c,v 1.176 2023/07/12 16:07:35 rillig Exp $ */
|
||||
/* $NetBSD: lex.c,v 1.177 2023/07/12 18:26:04 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: lex.c,v 1.176 2023/07/12 16:07:35 rillig Exp $");
|
||||
__RCSID("$NetBSD: lex.c,v 1.177 2023/07/12 18:26:04 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -148,7 +148,7 @@ static const struct keyword {
|
|||
kwdef_type( "__int128_t", INT128, 99),
|
||||
#endif
|
||||
kwdef_type( "long", LONG, 78),
|
||||
kwdef_token( "_Noreturn", T_NORETURN, 11,0,1),
|
||||
kwdef("_Noreturn", T_FUNCTION_SPECIFIER, .u.kw_fs = FS_NORETURN, 11,0,1),
|
||||
kwdef_token( "__packed", T_PACKED, 78,0,1),
|
||||
kwdef_token( "__real__", T_REAL, 78,1,1),
|
||||
kwdef_sclass( "register", REG, 78,0,1),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lint1.h,v 1.186 2023/07/12 16:07:35 rillig Exp $ */
|
||||
/* $NetBSD: lint1.h,v 1.187 2023/07/12 18:26:04 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
|
@ -210,8 +210,8 @@ typedef enum {
|
|||
|
||||
/* C23 6.7.4 */
|
||||
typedef enum {
|
||||
FS_INLINE,
|
||||
// TODO: Add FS_NORETURN, for C23.
|
||||
FS_INLINE, /* since C99 */
|
||||
FS_NORETURN, /* since C11 */
|
||||
} function_specifier;
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue