tests/lint: demonstrate wrong 'may lose accuracy' warning
Reported in PR 36668, fixed in sys/sys/endian.h 1.26 from 2007-07-20, unfixed in sys/sys/endian.h 1.29 from 2014-03-18.
This commit is contained in:
parent
fa370be1c7
commit
975e35506f
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msg_132.c,v 1.9 2022/04/21 19:48:18 rillig Exp $ */
|
||||
/* $NetBSD: msg_132.c,v 1.10 2022/05/26 07:03:03 rillig Exp $ */
|
||||
# 3 "msg_132.c"
|
||||
|
||||
// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
|
||||
|
@ -140,3 +140,37 @@ non_constant_expression(void)
|
|||
/* expect+1: warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132] */
|
||||
return not_a_constant * 8ULL;
|
||||
}
|
||||
|
||||
typedef unsigned char u8_t;
|
||||
typedef unsigned short u16_t;
|
||||
typedef unsigned int u32_t;
|
||||
typedef unsigned long long u64_t;
|
||||
|
||||
/*
|
||||
* PR 36668 notices that lint wrongly complains about the possible loss.
|
||||
* The expression 'uint8_t << 8' is guaranteed to fit into an 'unsigned short'.
|
||||
* 'unsigned short | unsigned char' is guaranteed to fit into 'unsigned short'
|
||||
*/
|
||||
static inline u16_t
|
||||
be16dec(const void *buf)
|
||||
{
|
||||
const u8_t *p = buf;
|
||||
|
||||
/* expect+1: warning: conversion from 'int' to 'unsigned short' may lose accuracy [132] */
|
||||
return ((u16_t)p[0]) << 8 | p[1];
|
||||
}
|
||||
|
||||
/*
|
||||
* Since tree.c 1.434 from 2022-04-19, lint infers the possible values of
|
||||
* expressions of the form 'integer & constant', see can_represent.
|
||||
*/
|
||||
static inline void
|
||||
be32enc(void *buf, u32_t u)
|
||||
{
|
||||
u8_t *p = buf;
|
||||
|
||||
p[0] = u >> 24 & 0xff;
|
||||
p[1] = u >> 16 & 0xff;
|
||||
p[2] = u >> 8 & 0xff;
|
||||
p[3] = u & 0xff;
|
||||
}
|
||||
|
|
|
@ -25,3 +25,4 @@ msg_132.c(99): warning: conversion from 'long long' to 'int' may lose accuracy [
|
|||
msg_132.c(125): error: operands of '+' have incompatible types (pointer != double) [107]
|
||||
msg_132.c(125): warning: function 'cover_build_plus_minus' expects to return value [214]
|
||||
msg_132.c(141): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]
|
||||
msg_132.c(160): warning: conversion from 'int' to 'unsigned short' may lose accuracy [132]
|
||||
|
|
Loading…
Reference in New Issue