Module Name: src
Committed By: rillig
Date: Fri Oct 4 11:24:13 UTC 2024
Modified Files:
src/tests/usr.bin/xlint/lint1: lex_comment.c
Log Message:
tests/lint: demonstrate ignored LINTED comment after if-else-if
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/lex_comment.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/lex_comment.c
diff -u src/tests/usr.bin/xlint/lint1/lex_comment.c:1.1 src/tests/usr.bin/xlint/lint1/lex_comment.c:1.2
--- src/tests/usr.bin/xlint/lint1/lex_comment.c:1.1 Sat Jun 19 20:25:58 2021
+++ src/tests/usr.bin/xlint/lint1/lex_comment.c Fri Oct 4 11:24:13 2024
@@ -1,13 +1,91 @@
-/* $NetBSD: lex_comment.c,v 1.1 2021/06/19 20:25:58 rillig Exp $ */
+/* $NetBSD: lex_comment.c,v 1.2 2024/10/04 11:24:13 rillig Exp $ */
# 3 "lex_comment.c"
/*
+ * Tests for comments, including lint-style comments that
+ * suppress a single diagnostic.
+ */
+
+/* lint1-extra-flags: -X 351 -aa */
+
+signed char s8;
+signed long long s64;
+
+// A "LINTED" comment suppresses a single warning until the end of the next
+// statement.
+void
+lint_comment(void)
+{
+ /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+ s8 = s64;
+
+ /* LINTED 132 */
+ s8 = s64;
+
+ /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+ s8 = s64;
+
+ /* LINTED 132 "comment" */
+ s8 = s64;
+
+ /* LINTED 132 */
+ {
+ }
+ /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+ s8 = s64;
+
+ /* LINTED 132 */
+ {
+ s8 = s64;
+ }
+ /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+ s8 = s64;
+
+ if (s8 == 0)
+ ;
+ /* LINTED 132 */
+ s8 = s64;
+
+ if (s8 == 0) {
+ }
+ /* LINTED 132 */
+ s8 = s64;
+
+ if (s8 == 0)
+ ;
+ else
+ ;
+ /* LINTED 132 */
+ s8 = s64;
+
+ if (s8 == 0) {
+ } else {
+ }
+ /* LINTED 132 */
+ s8 = s64;
+
+ if (s8 == 0) {
+ } else if (s8 == 1)
+ ;
+ /* LINTED 132 */
+ /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+ s8 = s64;
+
+ if (s8 == 0) {
+ } else if (s8 == 1) {
+ }
+ /* LINTED 132 */
+ /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+ s8 = s64;
+}
+
+
+/*
* Before lex.c 1.41 from 2021-06-19, lint ran into an endless loop when it
* saw an unclosed comment at the end of the translation unit. In practice
* this was not relevant since the translation unit always comes from the C
* preprocessor, which always emits a well-formed token sequence.
*/
-/* expect+3: error: unterminated comment [256] */
-/* expect+2: warning: empty translation unit [272] */
+/* expect+2: error: unterminated comment [256] */
/* unclosed comment