public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [committed] c: C2x enums wider than int [PR36113]
Date: Wed, 19 Oct 2022 01:55:58 +0200	[thread overview]
Message-ID: <Y089Dk5CirY1WlZJ@tucnak> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2210181407500.2354457@digraph.polyomino.org.uk>

On Tue, Oct 18, 2022 at 02:08:40PM +0000, Joseph Myers wrote:
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/c2x-enum-1.c
> @@ -0,0 +1,104 @@
> +/* Test C2x enumerations with values not representable in int.  */
> +/* { dg-do compile } */
> +/* { dg-options "-std=c2x -pedantic-errors" } */
> +
> +/* Check a type while defining an enum (via a diagnostic for incompatible
> +   pointer types if the wrong type was chosen).  */
> +#define TYPE_CHECK(cst, type)						\
> +  cst ## _type_check = sizeof (1 ? (type *) 0 : (typeof (cst) *) 0)
> +
...

> +/* Likewise, for overflow from long to long long.  */
> +#if __LONG_LONG_MAX__ > __LONG_MAX__
> +enum e5 { e5a = __LONG_MAX__,
> +	  e5b, e5c, e5d = ((typeof (e5b)) -1) < 0,
> +	  e5e = (unsigned long) -1,
> +	  e5f, e5g = ((typeof (e5e)) -1) > 0,
> +	  TYPE_CHECK (e5a, long), TYPE_CHECK (e5e, unsigned long) };

This fails on x86_64-linux with -m32 and I assume most other 32-bit
targets, it works with
	  TYPE_CHECK (e5a, int), TYPE_CHECK (e5e, unsigned long) };
Haven't checked in detail, but if int and long have the same bitsize,
doesn't __LONG_MAX__ fit into int and so this new handling of large
enumerators doesn't apply?
Can we just change that unconditionally, or shall it be conditional
on #if __LONG_MAX__ > __INT_MAX__ (then use long, otherwise int)?

	Jakub


  reply	other threads:[~2022-10-18 23:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 14:08 Joseph Myers
2022-10-18 23:55 ` Jakub Jelinek [this message]
2022-10-19 14:57   ` Joseph Myers
2022-10-19 16:22     ` [PATCH] testsuite: Fix up c2x-enum-1.c for 32-bit arches [PR107311] Jakub Jelinek
2022-10-19 16:28       ` Joseph Myers

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=Y089Dk5CirY1WlZJ@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /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).