Module Name: src Committed By: rillig Date: Sun Dec 15 05:56:18 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_222.c Log Message: tests/lint: add practical examples for signedness mismatch To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_222.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/msg_222.c diff -u src/tests/usr.bin/xlint/lint1/msg_222.c:1.6 src/tests/usr.bin/xlint/lint1/msg_222.c:1.7 --- src/tests/usr.bin/xlint/lint1/msg_222.c:1.6 Sat Jun 8 06:37:06 2024 +++ src/tests/usr.bin/xlint/lint1/msg_222.c Sun Dec 15 05:56:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_222.c,v 1.6 2024/06/08 06:37:06 rillig Exp $ */ +/* $NetBSD: msg_222.c,v 1.7 2024/12/15 05:56:18 rillig Exp $ */ # 3 "msg_222.c" // Test for message: conversion of negative constant %lld to unsigned type '%s' [222] @@ -11,7 +11,7 @@ unsigned int global = -1; void take_unsigned_int(unsigned int); void -function(void) +function(signed char *scp, unsigned char *ucp) { /* expect+1: warning: initialization of unsigned type 'unsigned int' with negative constant -1 [221] */ unsigned int local = -1; @@ -30,4 +30,14 @@ function(void) /* expect+1: warning: conversion of negative constant -1 to unsigned type 'unsigned int' [222] */ local += -1; + + *scp += 'A' - 'a'; + *scp -= 'A' - 'a'; + + // XXX: It's perfectly fine to effectively subtract a constant from + // XXX: an unsigned type. + /* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */ + *ucp += 'A' - 'a'; + /* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */ + *ucp -= 'A' - 'a'; }