From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 281FE3A53C17; Fri, 13 Nov 2020 14:55:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 281FE3A53C17 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/97798] FTB msp430-elf error: the value of '__gnu_cxx::__numeric_traits_integer<__int20>::__max' is not usable in a constant expression Date: Fri, 13 Nov 2020 14:55:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: build X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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: Fri, 13 Nov 2020 14:55:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97798 --- Comment #21 from CVS Commits --- The releases/gcc-9 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:62c2d527307d8adce31f5c9ca6e19e15b2866b83 commit r9-9045-g62c2d527307d8adce31f5c9ca6e19e15b2866b83 Author: Jonathan Wakely Date: Thu Nov 12 10:29:21 2020 +0000 libstdc++: Fix __numeric_traits_integer<__int20> [PR 97798] The expression used to calculate the maximum value for an integer type assumes that the number of bits in the value representation is always sizeof(T) * CHAR_BIT. This is not true for the __int20 type on msp430, which has only 20 bits in the value representation but 32 bits in the object representation. This causes an integer overflow in a constant expression, which is ill-formed. This problem was already solved by DJ for std::numeric_limits<__int20> by generalizing the helper macros to use a specified number of bits instead of assuming sizeof(T) * CHAR_BIT. Then the INT_N_n types can specify the number of bits using the __GLIBCXX_BITSIZE_INT_N_n macros that the compiler defines. I'm using a slightly different approach here. I've replaced the helper macros entirely, and just expanded the calculations in the initializers for the static data members. By reordering the data members we can reuse __is_signed and __digits in the other initializers. This removes the repetition of expanding __glibcxx_signed(T) and __glibcxx_digits(T) multiple times in each initializer. The __is_integer_nonstrict trait now defines a new constant, __width, which is sizeof(T) * CHAR_BIT by default (defined as an enumerator so that no storage is needed for a static data member). By specializing __is_integer_nonstrict for the INT_N types that have padding bits, we can provide the correct width via the __GLIBCXX_BITSIZE_INT_N_n macros. The backport for the gcc-9 branch adds the __is_integer_nonstrict trait, which was not previously present on the branch at all. libstdc++-v3/ChangeLog: PR libstdc++/97798 * include/ext/numeric_traits.h (__glibcxx_signed) (__glibcxx_digits, __glibcxx_min, __glibcxx_max): Remove macros. (__is_integer_nonstrict::__width): Define new constant. (__numeric_traits_integer): Define constants in terms of each other and __is_integer_nonstrict::__width, rather than the removed macros. (_GLIBCXX_INT_N_TRAITS): Macro to define explicit specializations for non-standard integer types. (cherry picked from commit 99f22a5ed91c7e4306b727f61c01484faf104115)=