tests/lint: test precedence of operators

This commit is contained in:
rillig 2021-07-15 17:09:08 +00:00
parent 582a074b3e
commit 60f9e3d3c0
4 changed files with 41 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1088 2021/07/14 20:39:13 rillig Exp $
# $NetBSD: mi,v 1.1089 2021/07/15 17:09:08 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -6224,6 +6224,8 @@
./usr/tests/usr.bin/xlint/lint1/emit.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.exp-ln tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.ln tests-obsolete obsolete
./usr/tests/usr.bin/xlint/lint1/expr_precedence.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_precedence.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c tests-usr.bin-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.89 2021/07/14 20:39:13 rillig Exp $
# $NetBSD: Makefile,v 1.90 2021/07/15 17:09:08 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 345 # see lint1/err.c
@ -123,6 +123,8 @@ FILES+= decl_struct_member.exp
FILES+= emit.c
FILES+= emit.exp
FILES+= emit.exp-ln
FILES+= expr_precedence.c
FILES+= expr_precedence.exp
FILES+= expr_range.c
FILES+= expr_range.exp
FILES+= feat_stacktrace.c

View File

@ -0,0 +1,31 @@
/* $NetBSD: expr_precedence.c,v 1.1 2021/07/15 17:09:08 rillig Exp $ */
# 3 "expr_precedence.c"
/*
* Tests for the precedence among operators.
*/
int var;
/*
* An initializer needs an assignment-expression; the comma must be
* interpreted as a separator, not an operator.
*/
/* expect+1: error: syntax error '4' [249] */
int init_error = 3, 4;
/* expect+1: error: non-constant initializer [177] */
int init_syntactically_ok = var = 1 ? 2 : 3;
/*
* The arguments of __attribute__ must be constant-expression, as assignments
* don't make sense at that point.
*/
void __attribute__((format(printf,
/* expect+2: error: 'var' undefined [99] */ /* XXX: why? */
/* XXX: allow only constant-expression, not assignment-expression */
var = 1,
/* Syntactically ok, must be a constant expression though. */
/* expect+1: error: 'var' undefined [99] */
var > 0 ? 2 : 1)))
my_printf(const char *, ...);

View File

@ -0,0 +1,4 @@
expr_precedence.c(15): error: syntax error '4' [249]
expr_precedence.c(18): error: non-constant initializer [177]
expr_precedence.c(27): error: 'var' undefined [99]
expr_precedence.c(30): error: 'var' undefined [99]