From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6AC7D38560A5; Mon, 30 May 2022 14:53:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AC7D38560A5 From: "dante19031999 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105775] New: GCC uses an invalid assumption in numeric limits of char Date: Mon, 30 May 2022 14:53:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: og11 (devel/omp/gcc-11) X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dante19031999 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 14:53:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105775 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 >=3D 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).=20 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=3Dtype-limits] 13 | __FULL_INLINE inline bool is_ascii( char cChar){return cChar >=3D 0= && cChar <=3D 127;} |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~ ./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=3Dtype-limits] 17 | __FULL_INLINE inline bool is_ascii_printable( char cChar){return cC= har >=3D 32 && cChar <=3D 127;} |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~ cc1: some warnings being treated as errors #define __FULL_INLINE __attribute__((__const__)) __attribute__((__nothrow__)) __attribute__((__always_inline__)) gcc -x c -std=3Dc17 -Wimplicit-function-declaration -pipe -Werror=3Dformat-= security -Wextra -Wall -pedantic -frounding-math -fsignaling-nans -Werror=3Dnarrowing -fPIC -Wunused-variable -Wunused-value -Wunused-but-set-variable -Og -std= =3Dgnu17 -I./ascii.h -c ./ascii.c -o ./instdir/ascii.c.o Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=3Dc,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=3D/usr --mandir=3D/usr/share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttp://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=3Dposix --enable-checking=3Drelease --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=3Dgnu --enable-plugin --enable-initfini-array --with-isl=3D/builddir/build/BUILD/gcc-11.3.1-20220421/obj-x86_64-redhat-li= nux/isl-install --enable-offload-targets=3Dnvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=3Dgeneric --with-arch_32=3Di686 --build=3Dx86_64-redhat-linux --with-build-config=3Dbootstrap-lto --enable-link-serialization=3D1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.3.1 20220421 (Red Hat 11.3.1-2) (GCC)=