Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: test declarations



details:   https://anonhg.NetBSD.org/src/rev/0267d0879d72
branches:  trunk
changeset: 984515:0267d0879d72
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 10 18:25:57 2021 +0000

description:
tests/lint: test declarations

diffstat:

 distrib/sets/lists/tests/mi        |   4 +-
 tests/usr.bin/xlint/lint1/Makefile |   4 +-
 tests/usr.bin/xlint/lint1/decl.c   |  73 ++++++++++++++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/decl.exp |  10 +++++
 4 files changed, 89 insertions(+), 2 deletions(-)

diffs (127 lines):

diff -r aef60d7b17db -r 0267d0879d72 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jul 10 18:13:06 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jul 10 18:25:57 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1082 2021/07/10 09:24:26 rillig Exp $
+# $NetBSD: mi,v 1.1083 2021/07/10 18:25:57 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6210,6 +6210,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_typefun.c                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_typename_as_var.c            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c          tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/decl.c                         tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/decl.exp                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/decl_arg.c                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/decl_arg.exp                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/decl_struct_member.c           tests-usr.bin-tests     compattestfile,atf
diff -r aef60d7b17db -r 0267d0879d72 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sat Jul 10 18:13:06 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sat Jul 10 18:25:57 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.83 2021/07/10 09:24:26 rillig Exp $
+# $NetBSD: Makefile,v 1.84 2021/07/10 18:25:57 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -108,6 +108,8 @@
 FILES+=                d_typefun.c
 FILES+=                d_typename_as_var.c
 FILES+=                d_zero_sized_arrays.c
+FILES+=                decl.c
+FILES+=                decl.exp
 FILES+=                decl_arg.c
 FILES+=                decl_arg.exp
 FILES+=                decl_struct_member.c
diff -r aef60d7b17db -r 0267d0879d72 tests/usr.bin/xlint/lint1/decl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.c  Sat Jul 10 18:25:57 2021 +0000
@@ -0,0 +1,73 @@
+/*     $NetBSD: decl.c,v 1.1 2021/07/10 18:25:57 rillig Exp $  */
+# 3 "decl.c"
+
+/*
+ * Tests for declarations, especially the distinction between the
+ * declaration-specifiers and the declarators.
+ */
+
+/*
+ * Even though 'const' comes after 'char' and is therefore quite close to the
+ * first identifier, it applies to both identifiers.
+ */
+void
+specifier_qualifier(void)
+{
+       char const a = 1, b = 2;
+
+       /* expect+1: warning: left operand of '=' must be modifiable lvalue [115] */
+       a = 1;
+       /* expect+1: warning: left operand of '=' must be modifiable lvalue [115] */
+       b = 2;
+}
+
+/*
+ * Since 'const' comes before 'char', there is no ambiguity whether the
+ * 'const' applies to all variables or just to the first.
+ */
+void
+qualifier_specifier(void)
+{
+       const char a = 1, b = 2;
+
+       /* expect+1: warning: left operand of '=' must be modifiable lvalue [115] */
+       a = 3;
+       /* expect+1: warning: left operand of '=' must be modifiable lvalue [115] */
+       b = 5;
+}
+
+void
+declarator_with_prefix_qualifier(void)
+{
+       /* expect+1: syntax error 'const' [249] */
+       char a = 1, const b = 2;
+
+       a = 1;
+       /* expect+1: error: 'b' undefined [99] */
+       b = 2;
+}
+
+void
+declarator_with_postfix_qualifier(void)
+{
+       /* expect+1: syntax error 'const' [249] */
+       char a = 1, b const = 2;
+
+       a = 1;
+       b = 2;
+}
+
+void sink(double *);
+
+void
+declarators(void)
+{
+       char *pc = 0, c = 0, **ppc = 0;
+
+       /* expect+1: warning: converting 'pointer to char' to incompatible 'pointer to double' */
+       sink(pc);
+       /* expect+1: warning: illegal combination of pointer (pointer to double) and integer (char) */
+       sink(c);
+       /* expect+1: converting 'pointer to pointer to char' to incompatible 'pointer to double' */
+       sink(ppc);
+}
diff -r aef60d7b17db -r 0267d0879d72 tests/usr.bin/xlint/lint1/decl.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.exp        Sat Jul 10 18:25:57 2021 +0000
@@ -0,0 +1,10 @@
+decl.c(19): warning: left operand of '=' must be modifiable lvalue [115]
+decl.c(21): warning: left operand of '=' must be modifiable lvalue [115]
+decl.c(34): warning: left operand of '=' must be modifiable lvalue [115]
+decl.c(36): warning: left operand of '=' must be modifiable lvalue [115]
+decl.c(43): error: syntax error 'const' [249]
+decl.c(47): error: 'b' undefined [99]
+decl.c(54): error: syntax error 'const' [249]
+decl.c(68): warning: converting 'pointer to char' to incompatible 'pointer to double' for argument 1 [153]
+decl.c(70): warning: illegal combination of pointer (pointer to double) and integer (char), arg #1 [154]
+decl.c(72): warning: converting 'pointer to pointer to char' to incompatible 'pointer to double' for argument 1 [153]



Home | Main Index | Thread Index | Old Index