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/lint1 tests/lint: demonstrate wrong warn...



details:   https://anonhg.NetBSD.org/src/rev/5b60be060f19
branches:  trunk
changeset: 365705:5b60be060f19
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Apr 19 19:56:29 2022 +0000

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

diffstat:

 tests/usr.bin/xlint/lint1/msg_298.c   |  23 ++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_298.exp |   6 +++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diffs (41 lines):

diff -r 278e3b4b720a -r 5b60be060f19 tests/usr.bin/xlint/lint1/msg_298.c
--- a/tests/usr.bin/xlint/lint1/msg_298.c       Tue Apr 19 09:25:38 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_298.c       Tue Apr 19 19:56:29 2022 +0000
@@ -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);
+}
diff -r 278e3b4b720a -r 5b60be060f19 tests/usr.bin/xlint/lint1/msg_298.exp
--- a/tests/usr.bin/xlint/lint1/msg_298.exp     Tue Apr 19 09:25:38 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_298.exp     Tue Apr 19 19:56:29 2022 +0000
@@ -1,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]



Home | Main Index | Thread Index | Old Index