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/234e254530d2
branches:  trunk
changeset: 374655:234e254530d2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue May 09 14:46:36 2023 +0000

description:
tests/lint: demonstrate wrong warning about losing accuracy

diffstat:

 tests/usr.bin/xlint/lint1/msg_132.c |  29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diffs (47 lines):

diff -r e32ab03eb032 -r 234e254530d2 tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Tue May 09 14:31:55 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Tue May 09 14:46:36 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.26 2023/03/28 14:44:34 rillig Exp $      */
+/*     $NetBSD: msg_132.c,v 1.27 2023/05/09 14:46:36 rillig Exp $      */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -24,6 +24,8 @@ typedef signed short s16_t;
 typedef signed int s32_t;
 typedef signed long long s64_t;
 
+_Bool cond;
+char ch;
 
 u8_t u8;
 u16_t u16;
@@ -365,3 +367,28 @@ test_ic_bitand(void)
        /* expect+1: warning: conversion from 'unsigned int' to 'unsigned char' may lose accuracy [132] */
        u8 = u16 & u32;
 }
+
+void
+test_ic_conditional(char c1, char c2)
+{
+       /* Both operands are representable as char. */
+       /* FIXME */
+       /* expect+1: warning: conversion from 'int' to 'char' may lose accuracy [132] */
+       ch = cond ? '?' : ':';
+
+       /*
+        * Both operands are representable as char. Clang-Tidy 17 wrongly
+        * warns about a narrowing conversion from 'int' to signed type
+        * 'char'.
+        */
+       /* FIXME */
+       /* expect+1: warning: conversion from 'int' to 'char' may lose accuracy [132] */
+       ch = cond ? c1 : c2;
+
+       /* FIXME */
+       /* expect+1: warning: conversion from 'int' to 'signed char' may lose accuracy [132] */
+       s8 = cond ? s8 : u8;
+
+       /* expect+1: warning: conversion from 'int' to 'unsigned char' may lose accuracy [132] */
+       u8 = cond ? s8 : u8;
+}



Home | Main Index | Thread Index | Old Index