public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100805] New: __int128 should be disabled for non-extended -std= options
@ 2021-05-27 20:39 dje at gcc dot gnu.org
  2021-05-27 21:36 ` [Bug c++/100805] " schwab@linux-m68k.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dje at gcc dot gnu.org @ 2021-05-27 20:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100805
           Summary: __int128 should be disabled for non-extended -std=
                    options
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dje at gcc dot gnu.org
  Target Milestone: ---

The __int128 extended type should not be enabled in strict standard mode, e.g.,
not gnu extended standard.

auto typechk = 0 ? 9223372036854775808 : -1;
unsigned long &typechk_p = &typeck;

64 bit mode:
error: cannot convert `__int128*' to `long unsigned int*' in initialization

32 bit mode:
error: invalid conversion from `long long int*' to `long long unsigned int*'
[-fpermissive]

using a signed type that is too small to preserve the value.

It seems that promoting the value to a type that is an extension is incorrect
in strict standard mode.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/100805] __int128 should be disabled for non-extended -std= options
  2021-05-27 20:39 [Bug c++/100805] New: __int128 should be disabled for non-extended -std= options dje at gcc dot gnu.org
@ 2021-05-27 21:36 ` schwab@linux-m68k.org
  2021-05-27 22:32 ` harald at gigawatt dot nl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: schwab@linux-m68k.org @ 2021-05-27 21:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
The C++ standard says: [lex.icon] "If an integer literal cannot be represented
by any type in its list and an extended integer type (6.8.1) can represent its
value, it may have that extended integer type."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/100805] __int128 should be disabled for non-extended -std= options
  2021-05-27 20:39 [Bug c++/100805] New: __int128 should be disabled for non-extended -std= options dje at gcc dot gnu.org
  2021-05-27 21:36 ` [Bug c++/100805] " schwab@linux-m68k.org
@ 2021-05-27 22:32 ` harald at gigawatt dot nl
  2021-05-28 16:38 ` redi at gcc dot gnu.org
  2023-08-08 10:19 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: harald at gigawatt dot nl @ 2021-05-27 22:32 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #2 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Andreas Schwab from comment #1)
> The C++ standard says: [lex.icon] "If an integer literal cannot be
> represented by any type in its list and an extended integer type (6.8.1) can
> represent its value, it may have that extended integer type."

__int128 behaves mostly like an integer type but is not an "extended integer
type" as defined in the standard. Quoting from
https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html: "GCC does not
support any extended integer types." Extended integer types must meet specific
requirements that __int128 does not meet: extended integer types cannot be
larger than intmax_t, and __int128 is.

Despite __int128 not being an extended integer type, there is nothing wrong
with having __int128 enabled in standards-conforming mode. Out-of-range
constants must be diagnosed, but they already are, and continuing to accept the
program after that is valid.

The warning that is generated for the out-of-range constant is highly
misleading though: the warning says "integer constant is so large that it is
unsigned". Either the constant should be given an unsigned type, or the warning
should be updated to reflect the type the constant actually gets.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/100805] __int128 should be disabled for non-extended -std= options
  2021-05-27 20:39 [Bug c++/100805] New: __int128 should be disabled for non-extended -std= options dje at gcc dot gnu.org
  2021-05-27 21:36 ` [Bug c++/100805] " schwab@linux-m68k.org
  2021-05-27 22:32 ` harald at gigawatt dot nl
@ 2021-05-28 16:38 ` redi at gcc dot gnu.org
  2023-08-08 10:19 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-28 16:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Harald van Dijk from comment #2)
> __int128 behaves mostly like an integer type but is not an "extended integer
> type" as defined in the standard. Quoting from
> https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html: "GCC does
> not support any extended integer types." Extended integer types must meet
> specific requirements that __int128 does not meet: extended integer types
> cannot be larger than intmax_t, and __int128 is.

Right.

> Despite __int128 not being an extended integer type, there is nothing wrong
> with having __int128 enabled in standards-conforming mode. Out-of-range
> constants must be diagnosed, but they already are, and continuing to accept
> the program after that is valid.

Indeed, a warning is a diagnostic.

> The warning that is generated for the out-of-range constant is highly
> misleading though: the warning says "integer constant is so large that it is
> unsigned". Either the constant should be given an unsigned type, or the
> warning should be updated to reflect the type the constant actually gets.

Agreed.

Going back to David's original point:
Whether or not the implicit conversion to __int128 is enabled for strict modes,
the __int128 type itself needs to be enabled. Libstdc++ relies on it existing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/100805] __int128 should be disabled for non-extended -std= options
  2021-05-27 20:39 [Bug c++/100805] New: __int128 should be disabled for non-extended -std= options dje at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-05-28 16:38 ` redi at gcc dot gnu.org
@ 2023-08-08 10:19 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-08 10:19 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=84764

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For C2x and C++23 __int128 can be an extended integer type, so we don't need to
pretend it doesn't exist.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-08 10:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 20:39 [Bug c++/100805] New: __int128 should be disabled for non-extended -std= options dje at gcc dot gnu.org
2021-05-27 21:36 ` [Bug c++/100805] " schwab@linux-m68k.org
2021-05-27 22:32 ` harald at gigawatt dot nl
2021-05-28 16:38 ` redi at gcc dot gnu.org
2023-08-08 10:19 ` redi at gcc dot gnu.org

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).