Module Name:    src
Committed By:   rillig
Date:           Tue Apr 19 19:56:30 UTC 2022

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_298.c msg_298.exp

Log Message:
tests/lint: demonstrate wrong warnings for conversion from long to char


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_298.c \
    src/tests/usr.bin/xlint/lint1/msg_298.exp

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_298.c
diff -u src/tests/usr.bin/xlint/lint1/msg_298.c:1.2 src/tests/usr.bin/xlint/lint1/msg_298.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_298.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_298.c	Tue Apr 19 19:56:29 2022
@@ -1,7 +1,24 @@
-/*	$NetBSD: msg_298.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_298.c,v 1.3 2022/04/19 19:56:29 rillig Exp $	*/
 # 3 "msg_298.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy, arg #%d [298]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -a */
+
+void take_uchar(unsigned char);
+void take_schar(signed char);
+
+void
+convert_bit_and(long l)
+{
+	/* expect+1: warning: conversion from 'long' to 'unsigned char' may lose accuracy, arg #1 [298] */
+	take_uchar(l);
+	/* expect+1: warning: conversion from 'long' to 'unsigned char' may lose accuracy, arg #1 [298] */
+	take_uchar(l & 0xFF);
+	/* expect+1: warning: conversion from 'long' to 'unsigned char' may lose accuracy, arg #1 [298] */
+	take_uchar(l & 0x100);
+	/* expect+1: warning: conversion from 'long' to 'signed char' may lose accuracy, arg #1 [298] */
+	take_schar(l & 0xFF);
+	/* expect+1: warning: conversion from 'long' to 'signed char' may lose accuracy, arg #1 [298] */
+	take_schar(l & 0x7F);
+}
Index: src/tests/usr.bin/xlint/lint1/msg_298.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_298.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_298.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_298.exp:1.2	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_298.exp	Tue Apr 19 19:56:29 2022
@@ -1 +1,5 @@
-msg_298.c(6): error: syntax error ':' [249]
+msg_298.c(15): warning: conversion from 'long' to 'unsigned char' may lose accuracy, arg #1 [298]
+msg_298.c(17): warning: conversion from 'long' to 'unsigned char' may lose accuracy, arg #1 [298]
+msg_298.c(19): warning: conversion from 'long' to 'unsigned char' may lose accuracy, arg #1 [298]
+msg_298.c(21): warning: conversion from 'long' to 'signed char' may lose accuracy, arg #1 [298]
+msg_298.c(23): warning: conversion from 'long' to 'signed char' may lose accuracy, arg #1 [298]

Reply via email to