Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint tests/lint: document placement of lint c...
details: https://anonhg.NetBSD.org/src/rev/04024b9526ee
branches: trunk
changeset: 1023397:04024b9526ee
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Sep 05 19:16:37 2021 +0000
description:
tests/lint: document placement of lint comments
diffstat:
tests/usr.bin/xlint/check-expect.lua | 7 ++++---
tests/usr.bin/xlint/lint1/msg_280.c | 33 +++++++++++++++++++++++++--------
tests/usr.bin/xlint/lint1/msg_280.exp | 12 ++++++------
3 files changed, 35 insertions(+), 17 deletions(-)
diffs (130 lines):
diff -r 72097b027017 -r 04024b9526ee tests/usr.bin/xlint/check-expect.lua
--- a/tests/usr.bin/xlint/check-expect.lua Sun Sep 05 18:39:58 2021 +0000
+++ b/tests/usr.bin/xlint/check-expect.lua Sun Sep 05 19:16:37 2021 +0000
@@ -1,5 +1,5 @@
#! /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.12 2021/08/21 07:49:48 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.13 2021/09/05 19:16:37 rillig Exp $
--[[
@@ -105,10 +105,11 @@
for _, act in ipairs(messages) do
local exp = comments_by_location[act.location] or {}
+ local exp_comment = act.message:gsub("/%*", "**"):gsub("%*/", "**")
local found = false
for i, message in ipairs(exp) do
- if message ~= "" and act.message:find(message, 1, true) then
+ if message ~= "" and exp_comment:find(message, 1, true) then
exp[i] = ""
found = true
break
@@ -116,7 +117,7 @@
end
if not found then
- errors:add("error: %s: missing /* expect+1: %s */", act.location, act.message)
+ errors:add("error: %s: missing /* expect+1: %s */", act.location, exp_comment)
end
end
diff -r 72097b027017 -r 04024b9526ee tests/usr.bin/xlint/lint1/msg_280.c
--- a/tests/usr.bin/xlint/lint1/msg_280.c Sun Sep 05 18:39:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_280.c Sun Sep 05 19:16:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_280.c,v 1.4 2021/09/05 18:39:58 rillig Exp $ */
+/* $NetBSD: msg_280.c,v 1.5 2021/09/05 19:16:37 rillig Exp $ */
# 3 "msg_280.c"
// Test for message: must be outside function: /* %s */ [280]
@@ -10,25 +10,42 @@
(void)str;
}
+/*
+ * In the following example, the comment looks misplaced, but lint does not
+ * warn about it.
+ *
+ * This is due to the implementation of the parser and the C grammar. When
+ * the parser sees the token T_LPAREN, it has to decide whether the following
+ * tokens will form a parameter type list or an identifier list. For that,
+ * it needs to look at the next token to see whether it is a T_NAME (in which
+ * case the T_LPAREN belongs to an id_list_lparen) or something else (in
+ * which case the T_LPAREN belongs to an abstract_decl_lparen). This token
+ * lookahead happens just before either of these grammar rules is reduced.
+ * During that reduction, the current declaration context switches from
+ * 'extern' to 'prototype argument', which makes this exact position the very
+ * last possible. Everything later would already be in the wrong context.
+ *
+ * As of cgram.y 1.360 from 2021-09-04, the implementation of these grammar
+ * rules is exactly the same, which makes it tempting to join them into a
+ * single rule.
+ */
void
-/* XXX: Why is this comment considered 'outside' enough? */
varargs_bad_param(/* VARARGS */ const char *str, ...)
{
(void)str;
}
void
-/* expect+1: warning: must be outside function: */
+/* expect+1: warning: must be outside function: ** VARARGS ** [280] */
varargs_bad_ellipsis(const char *str, /* VARARGS */ ...)
{
(void)str;
}
void
-/* XXX: Why is this comment considered 'outside' enough? */
varargs_bad_body(const char *str, ...)
{
- /* expect+1: warning: must be outside function */
+ /* expect+1: warning: must be outside function: ** VARARGS ** [280] */
/* VARARGS */
(void)str;
}
@@ -37,14 +54,14 @@
/* expect+1: warning: argument 'str' unused in function 'argsused_bad_body' [231] */
argsused_bad_body(const char *str)
{
- /* expect+1: warning: must be outside function */
+ /* expect+1: warning: must be outside function: ** ARGSUSED ** [280] */
/* ARGSUSED */
}
void
printflike_bad_body(const char *fmt, ...)
{
- /* expect+1: warning: must be outside function */
+ /* expect+1: warning: must be outside function: ** PRINTFLIKE ** [280] */
/* PRINTFLIKE */
(void)fmt;
}
@@ -52,7 +69,7 @@
void
scanflike_bad_body(const char *fmt, ...)
{
- /* expect+1: warning: must be outside function */
+ /* expect+1: warning: must be outside function: ** SCANFLIKE ** [280] */
/* SCANFLIKE */
(void)fmt;
}
diff -r 72097b027017 -r 04024b9526ee tests/usr.bin/xlint/lint1/msg_280.exp
--- a/tests/usr.bin/xlint/lint1/msg_280.exp Sun Sep 05 18:39:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_280.exp Sun Sep 05 19:16:37 2021 +0000
@@ -1,6 +1,6 @@
-msg_280.c(22): warning: must be outside function: /* VARARGS */ [280]
-msg_280.c(32): warning: must be outside function: /* VARARGS */ [280]
-msg_280.c(41): warning: must be outside function: /* ARGSUSED */ [280]
-msg_280.c(38): warning: argument 'str' unused in function 'argsused_bad_body' [231]
-msg_280.c(48): warning: must be outside function: /* PRINTFLIKE */ [280]
-msg_280.c(56): warning: must be outside function: /* SCANFLIKE */ [280]
+msg_280.c(40): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(49): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(58): warning: must be outside function: /* ARGSUSED */ [280]
+msg_280.c(55): warning: argument 'str' unused in function 'argsused_bad_body' [231]
+msg_280.c(65): warning: must be outside function: /* PRINTFLIKE */ [280]
+msg_280.c(73): warning: must be outside function: /* SCANFLIKE */ [280]
Home |
Main Index |
Thread Index |
Old Index