Module Name: src Committed By: rillig Date: Sat Sep 4 13:45:37 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_005.c msg_005.exp src/usr.bin/xlint/common: tyname.c src/usr.bin/xlint/lint1: decl.c Log Message: lint: reduce indentation in tdeferr No functional change. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_005.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_005.exp cvs rdiff -u -r1.46 -r1.47 src/usr.bin/xlint/common/tyname.c cvs rdiff -u -r1.232 -r1.233 src/usr.bin/xlint/lint1/decl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_005.c diff -u src/tests/usr.bin/xlint/lint1/msg_005.c:1.3 src/tests/usr.bin/xlint/lint1/msg_005.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_005.c:1.3 Sun Jan 31 11:12:07 2021 +++ src/tests/usr.bin/xlint/lint1/msg_005.c Sat Sep 4 13:45:37 2021 @@ -1,8 +1,29 @@ -/* $NetBSD: msg_005.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */ +/* $NetBSD: msg_005.c,v 1.4 2021/09/04 13:45:37 rillig Exp $ */ # 3 "msg_005.c" // Test for message: modifying typedef with '%s'; only qualifiers allowed [5] typedef int number; -number long long_variable; /* expect: 5 */ -number const const_variable; + +/* expect+1: warning: modifying typedef with 'signed'; only qualifiers allowed [5] */ +typedef number signed signed_number; + +/* expect+1: warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] */ +typedef number unsigned unsigned_number; + +/* expect+1: warning: modifying typedef with 'short'; only qualifiers allowed [5] */ +typedef number short short_number; + +/* expect+1: modifying typedef with 'long'; only qualifiers allowed [5] */ +typedef number long long_number; + +/* + * If the type qualifier comes first, the following name is interpreted as a + * new name, not as the one referring to the typedef. This makes the above + * type modifications even more obscure. + */ +/* expect+1: error: syntax error 'prefix_long_number' [249] */ +typedef long number prefix_long_number; + +/* Type qualifiers are OK. */ +typedef number const const_number; Index: src/tests/usr.bin/xlint/lint1/msg_005.exp diff -u src/tests/usr.bin/xlint/lint1/msg_005.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_005.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_005.exp:1.2 Sat Jan 2 18:06:01 2021 +++ src/tests/usr.bin/xlint/lint1/msg_005.exp Sat Sep 4 13:45:37 2021 @@ -1 +1,5 @@ -msg_005.c(7): warning: modifying typedef with 'long'; only qualifiers allowed [5] +msg_005.c(9): warning: modifying typedef with 'signed'; only qualifiers allowed [5] +msg_005.c(12): warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] +msg_005.c(15): warning: modifying typedef with 'short'; only qualifiers allowed [5] +msg_005.c(18): warning: modifying typedef with 'long'; only qualifiers allowed [5] +msg_005.c(26): error: syntax error 'prefix_long_number' [249] Index: src/usr.bin/xlint/common/tyname.c diff -u src/usr.bin/xlint/common/tyname.c:1.46 src/usr.bin/xlint/common/tyname.c:1.47 --- src/usr.bin/xlint/common/tyname.c:1.46 Tue Aug 31 23:49:21 2021 +++ src/usr.bin/xlint/common/tyname.c Sat Sep 4 13:45:36 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tyname.c,v 1.46 2021/08/31 23:49:21 rillig Exp $ */ +/* $NetBSD: tyname.c,v 1.47 2021/09/04 13:45:36 rillig Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tyname.c,v 1.46 2021/08/31 23:49:21 rillig Exp $"); +__RCSID("$NetBSD: tyname.c,v 1.47 2021/09/04 13:45:36 rillig Exp $"); #endif #include <limits.h> @@ -147,6 +147,7 @@ buf_add_int(buffer *buf, int n) buf_add(buf, num); } +/* XXX: at least partly redundant with ttab[t].tt_name */ const char * tspec_name(tspec_t t) { Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.232 src/usr.bin/xlint/lint1/decl.c:1.233 --- src/usr.bin/xlint/lint1/decl.c:1.232 Sat Sep 4 13:27:59 2021 +++ src/usr.bin/xlint/lint1/decl.c Sat Sep 4 13:45:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.232 2021/09/04 13:27:59 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.233 2021/09/04 13:45:37 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: decl.c,v 1.232 2021/09/04 13:27:59 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.233 2021/09/04 13:45:37 rillig Exp $"); #endif #include <sys/param.h> @@ -443,88 +443,51 @@ tdeferr(type_t *td, tspec_t t) t2 = td->t_tspec; - switch (t) { - case SIGNED: - case UNSIGN: - if (t2 == CHAR || t2 == SHORT || t2 == INT || t2 == LONG || - t2 == QUAD) { - if (!tflag) - /* modifying typedef with '%s'; only ... */ - warning(5, ttab[t].tt_name); - td = dup_type(gettyp(merge_signedness(t2, t))); - td->t_typedef = true; - return td; - } - break; - case SHORT: - if (t2 == INT || t2 == UINT) { - /* modifying typedef with '%s'; only qualifiers ... */ - warning(5, "short"); - td = dup_type(gettyp(t2 == INT ? SHORT : USHORT)); - td->t_typedef = true; - return td; - } - break; - case LONG: - if (t2 == INT || t2 == UINT || t2 == LONG || t2 == ULONG || - t2 == FLOAT || t2 == DOUBLE || t2 == DCOMPLEX) { - /* modifying typedef with '%s'; only qualifiers ... */ - warning(5, "long"); - if (t2 == INT) { - td = gettyp(LONG); - } else if (t2 == UINT) { - td = gettyp(ULONG); - } else if (t2 == LONG) { - td = gettyp(QUAD); - } else if (t2 == ULONG) { - td = gettyp(UQUAD); - } else if (t2 == FLOAT) { - td = gettyp(DOUBLE); - } else if (t2 == DOUBLE) { - td = gettyp(LDOUBLE); - } else if (t2 == DCOMPLEX) { - td = gettyp(LCOMPLEX); - } - td = dup_type(td); - td->t_typedef = true; - return td; - } - break; - /* LINTED206: (enumeration values not handled in switch) */ - case NOTSPEC: - case USHORT: - case UCHAR: - case SCHAR: - case CHAR: - case BOOL: - case FUNC: - case ARRAY: - case PTR: - case ENUM: - case UNION: - case STRUCT: - case VOID: - case LDOUBLE: - case FLOAT: - case DOUBLE: - case UQUAD: - case QUAD: -#ifdef INT128_SIZE - case UINT128: - case INT128: -#endif - case ULONG: - case UINT: - case INT: - case FCOMPLEX: - case DCOMPLEX: - case LCOMPLEX: - case COMPLEX: - break; + if ((t == SIGNED || t == UNSIGN) && + (t2 == CHAR || t2 == SHORT || t2 == INT || + t2 == LONG || t2 == QUAD)) { + if (!tflag) + /* modifying typedef with '%s'; only qualifiers... */ + warning(5, tspec_name(t)); + td = dup_type(gettyp(merge_signedness(t2, t))); + td->t_typedef = true; + return td; + } + + if (t == SHORT && (t2 == INT || t2 == UINT)) { + /* modifying typedef with '%s'; only qualifiers allowed */ + warning(5, "short"); + td = dup_type(gettyp(t2 == INT ? SHORT : USHORT)); + td->t_typedef = true; + return td; + } + + if (t == LONG && + (t2 == INT || t2 == UINT || t2 == LONG || t2 == ULONG || + t2 == FLOAT || t2 == DOUBLE || t2 == DCOMPLEX)) { + /* modifying typedef with '%s'; only qualifiers allowed */ + warning(5, "long"); + if (t2 == INT) { + td = gettyp(LONG); + } else if (t2 == UINT) { + td = gettyp(ULONG); + } else if (t2 == LONG) { + td = gettyp(QUAD); + } else if (t2 == ULONG) { + td = gettyp(UQUAD); + } else if (t2 == FLOAT) { + td = gettyp(DOUBLE); + } else if (t2 == DOUBLE) { + td = gettyp(LDOUBLE); + } else if (t2 == DCOMPLEX) { + td = gettyp(LCOMPLEX); + } + td = dup_type(td); + td->t_typedef = true; + return td; } - /* Anything other is not accepted. */ - + /* Anything else is not accepted. */ dcs->d_invalid_type_combination = true; return td; }