lint: fix wrong warning about losing accuracy when converting to _Bool

This commit is contained in:
rillig 2021-04-06 21:17:27 +00:00
parent ffb100ca4c
commit 4329029317
3 changed files with 12 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_132.c,v 1.4 2021/04/06 21:10:37 rillig Exp $ */
/* $NetBSD: msg_132.c,v 1.5 2021/04/06 21:17:28 rillig Exp $ */
# 3 "msg_132.c"
// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@ -63,9 +63,14 @@ convert_signed(i8 v8, i16 v16, i32 v32, i64 v64)
v64 = v32;
}
/*
* Before tree.c 1.268 from 2021-04-06, lint wrongly warned that conversion to
* _Bool might lose accuracy. C99 6.3.1.2 defines a special conversion rule
* from scalar to _Bool though.
*/
_Bool
to_bool(long a, long b)
{
/* seen in fp_lib.h, function wideRightShiftWithSticky */
return a | b; /* expect: 132 *//*FIXME*/
return a | b;
}

View File

@ -10,4 +10,3 @@ msg_132.c(51): warning: conversion from 'long long' to 'signed char' may lose ac
msg_132.c(54): warning: conversion from 'int' to 'short' may lose accuracy [132]
msg_132.c(55): warning: conversion from 'long long' to 'short' may lose accuracy [132]
msg_132.c(59): warning: conversion from 'long long' to 'int' may lose accuracy [132]
msg_132.c(70): warning: conversion from 'long' to '_Bool' may lose accuracy [132]

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.267 2021/04/06 13:17:04 rillig Exp $ */
/* $NetBSD: tree.c,v 1.268 2021/04/06 21:17:27 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.267 2021/04/06 13:17:04 rillig Exp $");
__RCSID("$NetBSD: tree.c,v 1.268 2021/04/06 21:17:27 rillig Exp $");
#endif
#include <float.h>
@ -1948,6 +1948,9 @@ check_integer_conversion(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp,
if (op == CVT)
return;
if (Sflag && nt == BOOL)
return; /* See C99 6.3.1.2 */
if (Pflag && portable_size_in_bits(nt) > portable_size_in_bits(ot) &&
is_uinteger(nt) != is_uinteger(ot)) {
if (aflag > 0 && pflag) {