Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: error out on missing type in decla...



details:   https://anonhg.NetBSD.org/src/rev/e5ab632c7050
branches:  trunk
changeset: 365783:e5ab632c7050
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 24 19:21:01 2022 +0000

description:
lint: error out on missing type in declarations

diffstat:

 tests/usr.bin/xlint/lint1/decl.c      |   4 ++--
 tests/usr.bin/xlint/lint1/decl.exp    |   1 +
 tests/usr.bin/xlint/lint1/emit.c      |   4 ++--
 tests/usr.bin/xlint/lint1/emit.exp    |   1 +
 tests/usr.bin/xlint/lint1/msg_007.c   |   7 +++++--
 tests/usr.bin/xlint/lint1/msg_007.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_030.c   |   5 ++++-
 tests/usr.bin/xlint/lint1/msg_030.exp |   9 ++++++---
 tests/usr.bin/xlint/lint1/msg_072.c   |   8 +++++++-
 tests/usr.bin/xlint/lint1/msg_072.exp |   2 ++
 usr.bin/xlint/lint1/cgram.y           |  15 +++++++++++----
 11 files changed, 43 insertions(+), 16 deletions(-)

diffs (183 lines):

diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/decl.c
--- a/tests/usr.bin/xlint/lint1/decl.c  Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.c  Sun Apr 24 19:21:01 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl.c,v 1.13 2022/04/03 10:05:23 rillig Exp $ */
+/*     $NetBSD: decl.c,v 1.14 2022/04/24 19:21:01 rillig Exp $ */
 # 3 "decl.c"
 
 /*
@@ -104,7 +104,7 @@
 declaration_without_type_specifier(void)
 {
        const i = 3;
-
+       /* expect-1: error: old style declaration; add 'int' [1] */
        return i;
 }
 
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/decl.exp
--- a/tests/usr.bin/xlint/lint1/decl.exp        Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.exp        Sun Apr 24 19:21:01 2022 +0000
@@ -9,6 +9,7 @@
 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]
 decl.c(80): error: syntax error '"' [249]
+decl.c(106): error: old style declaration; add 'int' [1]
 decl.c(163): error: syntax error 'int' [249]
 decl.c(166): error: syntax error 'int' [249]
 decl.c(180): error: syntax error 'goto' [249]
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/emit.c
--- a/tests/usr.bin/xlint/lint1/emit.c  Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.c  Sun Apr 24 19:21:01 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: emit.c,v 1.10 2022/01/15 14:22:03 rillig Exp $ */
+/*     $NetBSD: emit.c,v 1.11 2022/04/24 19:21:01 rillig Exp $ */
 # 3 "emit.c"
 
 /*
@@ -121,7 +121,7 @@
 
 extern void return_void_unknown_parameters();
 extern /* implicit int */ return_implicit_int_unknown_parameters();
-
+/* expect-1: error: old style declaration; add 'int' [1] */
 /* For function declarations, the keyword 'extern' is optional. */
 extern void extern_return_void_no_parameters(void);
 /* implicit extern */ void return_void_no_parameters(void);
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/emit.exp
--- a/tests/usr.bin/xlint/lint1/emit.exp        Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.exp        Sun Apr 24 19:21:01 2022 +0000
@@ -1,3 +1,4 @@
+emit.c(123): error: old style declaration; add 'int' [1]
 emit.c(108): warning: static variable static_int unused [226]
 emit.c(129): warning: static function static_return_void_no_parameters declared but not defined [290]
 emit.c(149): warning: static function static_function declared but not defined [290]
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/msg_007.c
--- a/tests/usr.bin/xlint/lint1/msg_007.c       Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_007.c       Sun Apr 24 19:21:01 2022 +0000
@@ -1,7 +1,10 @@
-/*     $NetBSD: msg_007.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_007.c,v 1.4 2022/04/24 19:21:01 rillig Exp $       */
 # 3 "msg_007.c"
 
 // Test for message: only one storage class allowed [7]
 
-extern static void example(void);      /* expect: 7 */
+/* expect+1: error: only one storage class allowed [7] */
+extern static void example(void);
+
+/* expect+1: error: old style declaration; add 'int' [1] */
 extern extern_function(void);
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/msg_007.exp
--- a/tests/usr.bin/xlint/lint1/msg_007.exp     Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_007.exp     Sun Apr 24 19:21:01 2022 +0000
@@ -1,1 +1,2 @@
-msg_007.c(6): error: only one storage class allowed [7]
+msg_007.c(7): error: only one storage class allowed [7]
+msg_007.c(10): error: old style declaration; add 'int' [1]
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/msg_030.c
--- a/tests/usr.bin/xlint/lint1/msg_030.c       Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_030.c       Sun Apr 24 19:21:01 2022 +0000
@@ -1,18 +1,21 @@
-/*     $NetBSD: msg_030.c,v 1.3 2022/04/05 23:09:19 rillig Exp $       */
+/*     $NetBSD: msg_030.c,v 1.4 2022/04/24 19:21:01 rillig Exp $       */
 # 3 "msg_030.c"
 
 /* Test for message: redeclaration of %s; ANSI C requires static [30] */
 
 /* lint1-flags: -sw */
 
+/* expect+1: error: old style declaration; add 'int' [1] */
 static a;
 /* expect+1: warning: redeclaration of a; ANSI C requires static [30] */
 int a;
 
+/* expect+1: error: old style declaration; add 'int' [1] */
 static b;
 /* expect+1: warning: redeclaration of b; ANSI C requires static [30] */
 int b = 1;
 
+/* expect+1: error: old style declaration; add 'int' [1] */
 static c = 1;
 /* expect+1: warning: redeclaration of c; ANSI C requires static [30] */
 int c;
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/msg_030.exp
--- a/tests/usr.bin/xlint/lint1/msg_030.exp     Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_030.exp     Sun Apr 24 19:21:01 2022 +0000
@@ -1,3 +1,6 @@
-msg_030.c(10): warning: redeclaration of a; ANSI C requires static [30]
-msg_030.c(14): warning: redeclaration of b; ANSI C requires static [30]
-msg_030.c(18): warning: redeclaration of c; ANSI C requires static [30]
+msg_030.c(9): error: old style declaration; add 'int' [1]
+msg_030.c(11): warning: redeclaration of a; ANSI C requires static [30]
+msg_030.c(14): error: old style declaration; add 'int' [1]
+msg_030.c(16): warning: redeclaration of b; ANSI C requires static [30]
+msg_030.c(19): error: old style declaration; add 'int' [1]
+msg_030.c(21): warning: redeclaration of c; ANSI C requires static [30]
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/msg_072.c
--- a/tests/usr.bin/xlint/lint1/msg_072.c       Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_072.c       Sun Apr 24 19:21:01 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_072.c,v 1.5 2021/07/14 20:39:13 rillig Exp $       */
+/*     $NetBSD: msg_072.c,v 1.6 2022/04/24 19:21:01 rillig Exp $       */
 # 3 "msg_072.c"
 
 // Test for message: typedef declares no type name [72]
@@ -26,4 +26,10 @@
 
        /* expect+1: warning: empty declaration [2] */
        int;
+
+       /* expect+1: error: syntax error 'missing base type for typedef' [249] */
+       typedef not_a_type;
+
+       /* expect+1: error: old style declaration; add 'int' [1] */
+       static missing_type;
 }
diff -r 9be63854d6de -r e5ab632c7050 tests/usr.bin/xlint/lint1/msg_072.exp
--- a/tests/usr.bin/xlint/lint1/msg_072.exp     Sun Apr 24 17:32:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_072.exp     Sun Apr 24 19:21:01 2022 +0000
@@ -4,3 +4,5 @@
 msg_072.c(22): warning: empty declaration [2]
 msg_072.c(25): warning: typedef declares no type name [72]
 msg_072.c(28): warning: empty declaration [2]
+msg_072.c(31): error: syntax error 'missing base type for typedef' [249]
+msg_072.c(34): error: old style declaration; add 'int' [1]
diff -r 9be63854d6de -r e5ab632c7050 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sun Apr 24 17:32:22 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sun Apr 24 19:21:01 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.400 2022/04/24 17:32:22 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.401 2022/04/24 19:21:01 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.400 2022/04/24 17:32:22 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.401 2022/04/24 19:21:01 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -745,8 +745,15 @@
                        warning(2);
                }
          }
-       | begin_type_declmods end_type notype_init_declarators T_SEMI
-       /* ^^ There is no check for the missing type-specifier. */
+       | begin_type_declmods end_type notype_init_declarators T_SEMI {
+               if (dcs->d_scl == TYPEDEF) {
+                       /* syntax error '%s' */
+                       error(249, "missing base type for typedef");
+               } else {
+                       /* old style declaration; add 'int' */
+                       error(1);
+               }
+         }
        | begin_type_declaration_specifiers end_type T_SEMI {
                if (dcs->d_scl == TYPEDEF) {
                        /* typedef declares no type name */



Home | Main Index | Thread Index | Old Index