lint: fix parsing of _Generic selection expressions
Previously, lint accepted comma-expressions where only assignment-expressions are allowed. This change does not make a difference in practice though since lint is usually only run on source code that properly compiles. Nevertheless, rather be precise and accurate since the grammar might some day be reused on less reliable input.
This commit is contained in:
parent
d4e4f03cef
commit
25b67a1f3a
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: c11_generic_expression.c,v 1.4 2021/06/27 21:16:40 rillig Exp $ */
|
||||
/* $NetBSD: c11_generic_expression.c,v 1.5 2021/06/27 21:30:46 rillig Exp $ */
|
||||
# 3 "c11_generic_expression.c"
|
||||
|
||||
/*
|
||||
|
@ -69,9 +69,9 @@ classify_char(char c)
|
|||
const int *
|
||||
comma_expression(char first, double second)
|
||||
{
|
||||
return _Generic(first, second, /* FIXME */
|
||||
return _Generic(first, second, /* expect: syntax error 'second' */
|
||||
char: "first",
|
||||
double: 2.0
|
||||
);
|
||||
/* expect-1: mismatch (pointer to const int) and (double) [211] */
|
||||
/* expect+1: without returning value [217] */
|
||||
}
|
||||
|
|
|
@ -2,4 +2,5 @@ c11_generic_expression.c(29): warning: function classify_type_without_default ex
|
|||
c11_generic_expression.c(21): warning: argument 'var' unused in function 'classify_type_without_default' [231]
|
||||
c11_generic_expression.c(37): warning: argument 'var' unused in function 'classify_type_with_default' [231]
|
||||
c11_generic_expression.c(53): warning: argument 'c' unused in function 'classify_char' [231]
|
||||
c11_generic_expression.c(75): error: return value type mismatch (pointer to const int) and (double) [211]
|
||||
c11_generic_expression.c(72): error: syntax error 'second' [249]
|
||||
c11_generic_expression.c(77): warning: function comma_expression falls off bottom without returning value [217]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
%{
|
||||
/* $NetBSD: cgram.y,v 1.237 2021/06/27 20:47:13 rillig Exp $ */
|
||||
/* $NetBSD: cgram.y,v 1.238 2021/06/27 21:30:46 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: cgram.y,v 1.237 2021/06/27 20:47:13 rillig Exp $");
|
||||
__RCSID("$NetBSD: cgram.y,v 1.238 2021/06/27 21:30:46 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -323,6 +323,7 @@ anonymize(sym_t *s)
|
|||
%type <y_sym> parameter_type_list
|
||||
%type <y_sym> parameter_declaration
|
||||
%type <y_tnode> expr
|
||||
%type <y_tnode> assignment_expression
|
||||
%type <y_tnode> gcc_statement_expr_list
|
||||
%type <y_tnode> gcc_statement_expr_item
|
||||
%type <y_tnode> term
|
||||
|
@ -1682,10 +1683,9 @@ switch_expr:
|
|||
}
|
||||
;
|
||||
|
||||
/* TODO: C11 6.5.1.1 says "assignment-expression", not plain "expr". */
|
||||
/* TODO: c11ism */
|
||||
generic_selection: /* C11 6.5.1.1 */
|
||||
T_GENERIC T_LPAREN expr T_COMMA generic_assoc_list T_RPAREN {
|
||||
T_GENERIC T_LPAREN assignment_expression T_COMMA
|
||||
generic_assoc_list T_RPAREN {
|
||||
/* generic selection requires C11 or later */
|
||||
c11ism(345);
|
||||
$$ = build_generic_selection($3, $5);
|
||||
|
@ -1911,6 +1911,10 @@ expr:
|
|||
}
|
||||
;
|
||||
|
||||
assignment_expression: /* C99 6.5.16 */
|
||||
expr %prec T_ASSIGN
|
||||
;
|
||||
|
||||
term:
|
||||
T_NAME {
|
||||
/* XXX really necessary? */
|
||||
|
|
Loading…
Reference in New Issue