From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 10A2E385800F; Tue, 18 Oct 2022 14:08:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10A2E385800F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666102103; bh=3mOhrKo1KgWTCe8QW89ZMG4FEJoqpnHXg2HVg5jhSc0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rD2yJ2TbUfsRLL8fQf48n36jrRfeRADjo1FdbSvu3SBl0JM+Jq2DSRwNpRnG8Lhd0 vPLBb3BwWjIptcPULwboGk2BhHTgU6LD3QqWEB5PoPk4O9uF1ieCiQcSn0oXWAyskd 9571Uqnza994o2gn8zBYwnQrwPi9W8UI2V4/n7gQ= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/36113] fix C enumerators Date: Tue, 18 Oct 2022 14:08:21 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.4.0 X-Bugzilla-Keywords: diagnostic, wrong-code X-Bugzilla-Severity: enhancement X-Bugzilla-Who: cvs-commit at gcc dot gnu.org 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D36113 --- Comment #7 from CVS Commits --- The master branch has been updated by Joseph Myers : https://gcc.gnu.org/g:3b3083a598ca3f4b6203284e01ed39ab6ff0844f commit r13-3360-g3b3083a598ca3f4b6203284e01ed39ab6ff0844f Author: Joseph Myers Date: Tue Oct 18 14:07:27 2022 +0000 c: C2x enums wider than int [PR36113] C2x has two enhancements to enumerations: allowing enumerations whose values do not all fit in int (similar to an existing extension), and allowing an underlying type to be specified (as in C++). This patch implements the first of those enhancements. Apart from adjusting diagnostics to reflect this being a standard feature, there are some semantics differences from the previous extension: * The standard feature gives all the values of such an enum the enumerated type (while keeping type int if that can represent all values of the enumeration), where previously GCC only gave those values outside the range of int the enumerated type. This change was previously requested in PR 36113; it seems unlikely that people are depending on the detail of the previous extension that some enumerators had different types to others depending on whether their values could be represented as int, and this patch makes the change to types of enumerators unconditionally (if that causes problems in practice we could always make it conditional on C2x mode instead). * The types *while the enumeration is being defined*, for enumerators that can't be represented as int, are now based more directly on the types of the expressions used, rather than a possibly different type with the right precision constructed using c_common_type_for_size. Again, this change is made unconditionally. * Where overflow (or wraparound to 0, in the case of an unsigned type) when 1 is implicitly added to determine the value of the next enumerator was previously an error, it now results in a wider type with the same signedness (as the while-being-defined type of the previous enumerator) being chosen, if available. When a type is chosen in such an overflow case, or when a type is chosen for the underlying integer type of the enumeration, it's possible that (unsigned) __int128 is chosen. Although C2x allows for such types wider than intmax_t to be considered extended integer types, we don't have various features required to do so (integer constant suffixes; sufficient library support would also be needed to define the associated macros for printf/scanf conversions, and typedef names would need to be defined). Thus, there are also pedwarns for exceeding the range of intmax_t / uintmax_t, as while in principle exceeding that range is OK, it's only OK in a context where the relevant types meet the requirements for extended integer types, which does not currently apply here. Bootstrapped with no regressions for x86_64-pc-linux-gnu. Also manually checked diagnostics for c2x-enum-3.c with -m32 to confirm the diagnostics in that { target { ! int128 } } test are as expected. PR c/36113 gcc/c-family/ * c-common.cc (c_common_type_for_size): Add fallback to widest_unsigned_literal_type_node or widest_integer_literal_type_node for precision that may not exactly match the precision of those types. gcc/c/ * c-decl.cc (finish_enum): If any enumerators do not fit in int, convert all to the type of the enumeration. pedwarn if no inte= ger type fits all enumerators and default to widest_integer_literal_type_node in that case. Otherwise pedwa= rn for type wider than intmax_t. (build_enumerator): pedwarn for enumerators outside the range of uintmax_t or intmax_t, and otherwise use pedwarn_c11 for enumerators outside the range of int. On overflow, attempt to find a wider type that can hold the value of the next enumerato= r. Do not convert value to type determined with c_common_type_for_size. gcc/testsuite/ * gcc.dg/c11-enum-1.c, gcc.dg/c11-enum-2.c, gcc.dg/c11-enum-3.c, gcc.dg/c2x-enum-1.c, gcc.dg/c2x-enum-2.c, gcc.dg/c2x-enum-3.c, gcc.dg/c2x-enum-4.c, gcc.dg/c2x-enum-5.c: New tests. * gcc.dg/pr30260.c: Explicitly use -std=3Dgnu11. Update expect= ed diagnostics. * gcc.dg/torture/pr25183.c: Update expected diagnostics.=