public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.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: Thu, 12 Nov 2020 12:11:26 +0000	[thread overview]
Message-ID: <bug-97798-4-bcVR5yJiXo@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97798-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97798

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:7f851c33411fc39982c62a91fa93ec02981fd956

commit r11-4941-g7f851c33411fc39982c62a91fa93ec02981fd956
Author: Jonathan Wakely <jwakely@redhat.com>
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.

    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.

  parent reply	other threads:[~2020-11-12 12:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11 13:55 [Bug c++/97798] New: " jozefl at gcc dot gnu.org
2020-11-11 14:38 ` [Bug c++/97798] " mpolacek at gcc dot gnu.org
2020-11-11 14:56 ` jozefl at gcc dot gnu.org
2020-11-11 15:26 ` mpolacek at gcc dot gnu.org
2020-11-11 15:51 ` mpolacek at gcc dot gnu.org
2020-11-11 18:37 ` mpolacek at gcc dot gnu.org
2020-11-12  0:03 ` redi at gcc dot gnu.org
2020-11-12  0:36 ` [Bug libstdc++/97798] " redi at gcc dot gnu.org
2020-11-12  0:38 ` redi at gcc dot gnu.org
2020-11-12 10:00 ` jozefl at gcc dot gnu.org
2020-11-12 12:11 ` cvs-commit at gcc dot gnu.org [this message]
2020-11-12 12:13 ` redi at gcc dot gnu.org
2020-11-12 12:30 ` jozefl at gcc dot gnu.org
2020-11-12 14:27 ` redi at gcc dot gnu.org
2020-11-12 16:06 ` jozefl at gcc dot gnu.org
2020-11-12 17:43 ` redi at gcc dot gnu.org
2020-11-12 19:31 ` jozefl at gcc dot gnu.org
2020-11-12 19:32 ` redi at gcc dot gnu.org
2020-11-13 13:24 ` redi at gcc dot gnu.org
2020-11-13 13:49 ` jozefl at gcc dot gnu.org
2020-11-13 14:52 ` cvs-commit at gcc dot gnu.org
2020-11-13 14:55 ` cvs-commit at gcc dot gnu.org
2020-11-13 14:57 ` redi at gcc dot gnu.org
2020-11-13 15:12 ` jozefl at gcc dot gnu.org
2020-11-13 15:30 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97798-4-bcVR5yJiXo@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).