[Bug c/105775] New: GCC uses an invalid assumption in numeric limits of char
dante19031999 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon May 30 14:53:31 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105775
Bug ID: 105775
Summary: GCC uses an invalid assumption in numeric limits of
char
Product: gcc
Version: og11 (devel/omp/gcc-11)
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: dante19031999 at gmail dot com
Target Milestone: ---
On my system char is defined as a signed char which means that the limit is
indeed 127.
However in the C standard it is false, therefor there is an error.
This affects the use of the code for cross platform purposes.
Most probably you will find the complementary error in platforms where char is
defined as unsigned char giving the warning on cChar >= 0.
The error can be avoided to a certain extent with #if CHAR_MIN < 0 or
conversion to unsigned char...
The code shown here is a simplified version of the original made for the
purpose of the bug report.
According to cppreference:
signed char - type for signed character representation.
unsigned char - type for unsigned character representation. Also used to
inspect object representations (raw memory).
char - type for character representation. Equivalent to either signed char or
unsigned char (which one is implementation-defined and may be controlled by a
compiler command line switch), but char is a distinct type, different from both
signed char and unsigned char.
./inc/ascii.h: In function 'is_ascii':
./inc/ascii.h:13:89: error: comparison is always true due to limited range of
data type [-Werror=type-limits]
13 | __FULL_INLINE inline bool is_ascii( char cChar){return cChar >= 0 &&
cChar <= 127;}
|
^~
./inc/ascii.h: In function 'is_ascii_printable':
./inc/ascii.h:17:94: error: comparison is always true due to limited range of
data type [-Werror=type-limits]
17 | __FULL_INLINE inline bool is_ascii_printable( char cChar){return cChar
>= 32 && cChar <= 127;}
|
^~
cc1: some warnings being treated as errors
#define __FULL_INLINE __attribute__((__const__))
__attribute__((__nothrow__)) __attribute__((__always_inline__))
gcc -x c -std=c17 -Wimplicit-function-declaration -pipe -Werror=format-security
-Wextra -Wall -pedantic -frounding-math -fsignaling-nans -Werror=narrowing
-fPIC -Wunused-variable -Wunused-value -Wunused-but-set-variable -Og -std=gnu17
-I./ascii.h -c ./ascii.c -o ./instdir/ascii.c.o
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-11.3.1-20220421/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.1 20220421 (Red Hat 11.3.1-2) (GCC)
More information about the Gcc-bugs
mailing list