[clang] [clang][C23] Support N3029 Improved Normal Enumerations (PR #103917)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 2 05:48:06 PDT 2024
https://github.com/Fznamznon updated https://github.com/llvm/llvm-project/pull/103917
>From eee57bcc211a8a045c0102ebb2f4410d52d657f6 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" <mariya.podchishchaeva at intel.com>
Date: Wed, 14 Aug 2024 05:56:18 -0700
Subject: [PATCH 1/3] [clang][C23] Support N3029 Improved Normal Enumerations
Basically clang already implemented 90% of the feature as an extension.
This commit disables warnings for C23 and aligns types of enumerators
according to the recent wording.
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Sema/SemaDecl.cpp | 44 +++++++++++++++------------
clang/test/C/C23/n3029.c | 59 +++++++++++++++++++++++++++++++++++++
clang/test/Sema/enum.c | 52 +++++++++++++++++++++++++-------
clang/www/c_status.html | 2 +-
5 files changed, 129 insertions(+), 30 deletions(-)
create mode 100644 clang/test/C/C23/n3029.c
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6796a619ba97f8..376ed0facc8504 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -125,6 +125,8 @@ C2y Feature Support
C23 Feature Support
^^^^^^^^^^^^^^^^^^^
+- Clang now supports `N3029 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm>`_ Improved Normal Enumerations.
+
Non-comprehensive list of changes in this release
-------------------------------------------------
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 641b180527da55..03f14487d0b80e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19474,11 +19474,12 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
// representable as an int.
// Complain if the value is not representable in an int.
- if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
- Diag(IdLoc, diag::ext_enum_value_not_int)
- << toString(EnumVal, 10) << Val->getSourceRange()
- << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
- else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
+ if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy)) {
+ if (!getLangOpts().C23)
+ Diag(IdLoc, diag::ext_enum_value_not_int)
+ << toString(EnumVal, 10) << Val->getSourceRange()
+ << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+ } else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
// Force the type of the expression to 'int'.
Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
}
@@ -19553,12 +19554,12 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
// If we're not in C++, diagnose the overflow of enumerator values,
// which in C99 means that the enumerator value is not representable in
- // an int (C99 6.7.2.2p2). However, we support GCC's extension that
- // permits enumerator values that are representable in some larger
- // integral type.
- if (!getLangOpts().CPlusPlus && !T.isNull())
+ // an int (C99 6.7.2.2p2). However C23 permits enumerator values that
+ // are representable in some larger integral type and we allow it in
+ // older language modes as an extension.
+ if (!getLangOpts().CPlusPlus && !getLangOpts().C23 && !T.isNull())
Diag(IdLoc, diag::warn_enum_value_overflow);
- } else if (!getLangOpts().CPlusPlus &&
+ } else if (!getLangOpts().CPlusPlus && !getLangOpts().C23 &&
!EltTy->isDependentType() &&
!isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
// Enforce C99 6.7.2.2p2 even when we compute the next value.
@@ -19882,9 +19883,6 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
return;
}
- // TODO: If the result value doesn't fit in an int, it must be a long or long
- // long value. ISO C does not support this, but GCC does as an extension,
- // emit a warning.
unsigned IntWidth = Context.getTargetInfo().getIntWidth();
unsigned CharWidth = Context.getTargetInfo().getCharWidth();
unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
@@ -19893,13 +19891,14 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
// reverse the list.
unsigned NumNegativeBits = 0;
unsigned NumPositiveBits = 0;
+ bool MembersRepresentableByInt = true;
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
EnumConstantDecl *ECD =
cast_or_null<EnumConstantDecl>(Elements[i]);
if (!ECD) continue; // Already issued a diagnostic.
- const llvm::APSInt &InitVal = ECD->getInitVal();
+ llvm::APSInt InitVal = ECD->getInitVal();
// Keep track of the size of positive and negative values.
if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
@@ -19911,6 +19910,8 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
NumNegativeBits =
std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
}
+ MembersRepresentableByInt &=
+ isRepresentableIntegerValue(Context, InitVal, Context.IntTy);
}
// If we have an empty set of enumerators we still need one bit.
@@ -19932,7 +19933,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
// int, long long int, or unsigned long long int.
// C99 6.4.4.3p2:
// An identifier declared as an enumeration constant has type int.
- // The C99 rule is modified by a gcc extension
+ // The C99 rule is modified by C23.
QualType BestPromotionType;
bool Packed = Enum->hasAttr<PackedAttr>();
@@ -20026,7 +20027,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
auto *ECD = cast_or_null<EnumConstantDecl>(D);
if (!ECD) continue; // Already issued a diagnostic.
- // Standard C says the enumerators have int type, but we allow, as an
+ // C99 says the enumerators have int type, but we allow, as an
// extension, the enumerators to be larger than int size. If each
// enumerator value fits in an int, type it as an int, otherwise type it the
// same as the enumerator decl itself. This means that in "enum { X = 1U }"
@@ -20040,9 +20041,14 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
QualType NewTy;
unsigned NewWidth;
bool NewSign;
- if (!getLangOpts().CPlusPlus &&
- !Enum->isFixed() &&
- isRepresentableIntegerValue(Context, InitVal, Context.IntTy)) {
+ if (!getLangOpts().CPlusPlus && !Enum->isFixed() &&
+ MembersRepresentableByInt) {
+ // C23 6.7.3.3.3p15:
+ // The enumeration member type for an enumerated type without fixed
+ // underlying type upon completion is:
+ // - int if all the values of the enumeration are representable as an
+ // int; or,
+ // - the enumerated type
NewTy = Context.IntTy;
NewWidth = IntWidth;
NewSign = true;
diff --git a/clang/test/C/C23/n3029.c b/clang/test/C/C23/n3029.c
new file mode 100644
index 00000000000000..d0dccb02501133
--- /dev/null
+++ b/clang/test/C/C23/n3029.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -verify -fsyntax-only --embed-dir=%S/Inputs -std=c23 %s -pedantic
+
+#include <limits.h>
+
+#define GET_TYPE_INT(x) _Generic(x, \
+ char: 1,\
+ unsigned char: 2,\
+ signed char: 3,\
+ short: 4,\
+ unsigned short: 5,\
+ int: 6,\
+ unsigned int: 7,\
+ long: 8,\
+ unsigned long: 9,\
+ long long: 10,\
+ unsigned long long: 11,\
+ default: 0xFF\
+ )\
+
+enum x {
+a = INT_MAX,
+b = ULLONG_MAX,
+a_type = GET_TYPE_INT(a),
+b_type = GET_TYPE_INT(b)
+};
+
+static_assert(GET_TYPE_INT(a) == GET_TYPE_INT(b));
+
+extern enum x e_a;
+extern __typeof(b) e_a;
+extern __typeof(a) e_a;
+
+enum a {
+ a0 = 0xFFFFFFFFFFFFFFFFULL
+};
+
+_Bool e () {
+ return a0;
+}
+
+int f () {
+ return a0; // expected-warning {{implicit conversion from 'unsigned long' to 'int' changes value from 18446744073709551615 to -1}}
+}
+
+unsigned long g () {
+ return a0;
+}
+
+unsigned long long h () {
+ return a0;
+}
+
+enum big_enum {
+ big_enum_a = LONG_MAX,
+ big_enum_b = a + 1,
+ big_enum_c = ULLONG_MAX
+};
+
+static_assert(GET_TYPE_INT(big_enum_a) == GET_TYPE_INT(big_enum_b));
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index b0707914c0d852..d2cd27a0c02299 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -1,23 +1,23 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify -pedantic
+// RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify=expected,c99 -pedantic
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -fsyntax-only -std=c23 -verify -pedantic
enum e {A,
- B = 42LL << 32, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+ B = 42LL << 32, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
C = -4, D = 12456 };
enum f { a = -2147483648, b = 2147483647 }; // ok.
enum g { // too negative
- c = -2147483649, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+ c = -2147483649, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
d = 2147483647 };
enum h { e = -2147483648, // too pos
- f = 2147483648, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
- i = 0xFFFF0000 // expected-warning {{too large}}
+ f = 2147483648, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
+ i = 0xFFFF0000 // c99-warning {{too large}}
};
// minll maxull
enum x // expected-warning {{enumeration values exceed range of largest integer}}
-{ y = -9223372036854775807LL-1, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
-z = 9223372036854775808ULL }; // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+{ y = -9223372036854775807LL-1, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
+z = 9223372036854775808ULL }; // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
int test(void) {
return sizeof(enum e) ;
@@ -172,10 +172,8 @@ enum class GH42372_2 {
#if __STDC_VERSION__ >= 202311L
// FIXME: GCC picks __uint128_t as the underlying type for the enumeration
// value and Clang picks unsigned long long.
-// FIXME: Clang does not yet implement WG14 N3029, so the warning about
-// restricting enumerator values to 'int' is not correct.
enum GH59352 { // expected-warning {{enumeration values exceed range of largest integer}}
- BigVal = 66666666666666666666wb // expected-warning {{ISO C restricts enumerator values to range of 'int' (66666666666666666666 is too large)}}
+ BigVal = 66666666666666666666wb // c99-warning {{ISO C restricts enumerator values to range of 'int' (66666666666666666666 is too large)}}
};
_Static_assert(BigVal == 66666666666666666666wb); /* expected-error {{static assertion failed due to requirement 'BigVal == 66666666666666666666wb'}}
expected-note {{expression evaluates to '11326434445538011818 == 66666666666666666666'}}
@@ -191,4 +189,38 @@ _Static_assert(
__uint128_t : 1
)
);
+
+#include <limits.h>
+
+void fooinc23() {
+ enum E1 {
+ V1 = INT_MAX
+ } e1;
+
+ enum E2 {
+ V2 = INT_MAX,
+ V3
+ } e2;
+
+ enum E3 {
+ V4 = INT_MAX,
+ V5 = LONG_MIN
+ } e3;
+
+ enum E4 {
+ V6 = 1u,
+ V7 = 2wb
+ } e4;
+
+ _Static_assert(_Generic(V1, int : 1));
+ _Static_assert(_Generic(V2, int : 0, unsigned int : 1));
+ _Static_assert(_Generic(V3, int : 0, unsigned int : 1));
+ _Static_assert(_Generic(V4, int : 0, signed long : 1));
+ _Static_assert(_Generic(V5, int : 0, signed long : 1));
+ _Static_assert(_Generic(V6, int : 1));
+ _Static_assert(_Generic(V7, int : 1));
+ _Static_assert(_Generic((enum E4){}, unsigned int : 1));
+
+}
+
#endif // __STDC_VERSION__ >= 202311L
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index a5d04506b642bc..cc2c83d5225e98 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1160,7 +1160,7 @@ <h2 id="c2x">C23 implementation status</h2>
<tr>
<td>Improved normal enumerations</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3029.htm">N3029</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="unreleased" align="center">Clang 20</td>
</tr>
<tr>
<td>Relax requirements for va_start</td>
>From d766f1924d3724eb13c1b50e2018a0f3becefabb Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" <mariya.podchishchaeva at intel.com>
Date: Thu, 15 Aug 2024 03:47:15 -0700
Subject: [PATCH 2/3] Fix test on Windows
---
clang/test/C/C23/n3029.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/C/C23/n3029.c b/clang/test/C/C23/n3029.c
index d0dccb02501133..b5c331ab96c4de 100644
--- a/clang/test/C/C23/n3029.c
+++ b/clang/test/C/C23/n3029.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only --embed-dir=%S/Inputs -std=c23 %s -pedantic
+// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only --embed-dir=%S/Inputs -std=c23 %s -pedantic
#include <limits.h>
>From 06c369998e8d2e3d1ea4b409f141928fc507503c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" <mariya.podchishchaeva at intel.com>
Date: Mon, 2 Sep 2024 05:02:33 -0700
Subject: [PATCH 3/3] Add -Wpre-c23-compat warning
---
clang/docs/ReleaseNotes.rst | 2 +-
.../include/clang/Basic/DiagnosticSemaKinds.td | 9 ++++++---
clang/lib/Sema/SemaDecl.cpp | 18 ++++++++++--------
clang/test/C/C23/n3029.c | 16 ++++++++--------
clang/test/Misc/warning-flags.c | 2 +-
clang/test/Sema/enum.c | 10 +++++-----
6 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 376ed0facc8504..6af7769177ecbe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -125,7 +125,7 @@ C2y Feature Support
C23 Feature Support
^^^^^^^^^^^^^^^^^^^
-- Clang now supports `N3029 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm>`_ Improved Normal Enumerations.
+- Clang now supports `N3029 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3029.htm>`_ Improved Normal Enumerations.
Non-comprehensive list of changes in this release
-------------------------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 554dbaff2ce0d8..fa2ba4400ae052 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6185,9 +6185,12 @@ def err_misplaced_ivar : Error<
def warn_ivars_in_interface : Warning<
"declaration of instance variables in the interface is deprecated">,
InGroup<DiagGroup<"objc-interface-ivars">>, DefaultIgnore;
-def ext_enum_value_not_int : Extension<
- "ISO C restricts enumerator values to range of 'int' (%0 is too "
- "%select{small|large}1)">;
+def ext_c23_enum_value_not_int : Extension<
+ "enumerator values exceeding range of 'int' is a C23 extension (%0 is too "
+ "%select{small|large}1)">, InGroup<C23>;
+def warn_c17_compat_enum_value_not_int : Warning<
+ "enumerator values exceeding range of 'int' is incompatible with C standards before C23 (%0 is too "
+ "%select{small|large}1)">, DefaultIgnore, InGroup<CPre23Compat>;
def ext_enum_too_large : ExtWarn<
"enumeration values exceed range of largest integer">, InGroup<EnumTooLarge>;
def ext_enumerator_increment_too_large : ExtWarn<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 03f14487d0b80e..d7e8e536431656 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19475,10 +19475,11 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
// Complain if the value is not representable in an int.
if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy)) {
- if (!getLangOpts().C23)
- Diag(IdLoc, diag::ext_enum_value_not_int)
- << toString(EnumVal, 10) << Val->getSourceRange()
- << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+ Diag(IdLoc, (getLangOpts().C23)
+ ? diag::warn_c17_compat_enum_value_not_int
+ : diag::ext_c23_enum_value_not_int)
+ << toString(EnumVal, 10) << Val->getSourceRange()
+ << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
} else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
// Force the type of the expression to 'int'.
Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
@@ -19559,12 +19560,13 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
// older language modes as an extension.
if (!getLangOpts().CPlusPlus && !getLangOpts().C23 && !T.isNull())
Diag(IdLoc, diag::warn_enum_value_overflow);
- } else if (!getLangOpts().CPlusPlus && !getLangOpts().C23 &&
- !EltTy->isDependentType() &&
+ } else if (!getLangOpts().CPlusPlus && !EltTy->isDependentType() &&
!isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
// Enforce C99 6.7.2.2p2 even when we compute the next value.
- Diag(IdLoc, diag::ext_enum_value_not_int)
- << toString(EnumVal, 10) << 1;
+ Diag(IdLoc, (getLangOpts().C23)
+ ? diag::warn_c17_compat_enum_value_not_int
+ : diag::ext_c23_enum_value_not_int)
+ << toString(EnumVal, 10) << 1;
}
}
}
diff --git a/clang/test/C/C23/n3029.c b/clang/test/C/C23/n3029.c
index b5c331ab96c4de..40d23472c4bdcd 100644
--- a/clang/test/C/C23/n3029.c
+++ b/clang/test/C/C23/n3029.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only --embed-dir=%S/Inputs -std=c23 %s -pedantic
+// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only --embed-dir=%S/Inputs -std=c23 %s -pedantic -Wpre-c23-compat
#include <limits.h>
@@ -19,19 +19,19 @@
enum x {
a = INT_MAX,
-b = ULLONG_MAX,
+b = ULLONG_MAX, // expected-warning {{enumerator values exceeding range of 'int' is incompatible with C standards before C23}}
a_type = GET_TYPE_INT(a),
b_type = GET_TYPE_INT(b)
};
-static_assert(GET_TYPE_INT(a) == GET_TYPE_INT(b));
+_Static_assert(GET_TYPE_INT(a) == GET_TYPE_INT(b), "ok");
extern enum x e_a;
extern __typeof(b) e_a;
extern __typeof(a) e_a;
enum a {
- a0 = 0xFFFFFFFFFFFFFFFFULL
+ a0 = 0xFFFFFFFFFFFFFFFFULL // expected-warning {{enumerator values exceeding range of 'int' is incompatible with C standards before C23}}
};
_Bool e () {
@@ -51,9 +51,9 @@ unsigned long long h () {
}
enum big_enum {
- big_enum_a = LONG_MAX,
- big_enum_b = a + 1,
- big_enum_c = ULLONG_MAX
+ big_enum_a = LONG_MAX, // expected-warning {{enumerator values exceeding range of 'int' is incompatible with C standards before C23}}
+ big_enum_b = a + 1, // expected-warning {{enumerator values exceeding range of 'int' is incompatible with C standards before C23}}
+ big_enum_c = ULLONG_MAX // expected-warning {{enumerator values exceeding range of 'int' is incompatible with C standards before C23}}
};
-static_assert(GET_TYPE_INT(big_enum_a) == GET_TYPE_INT(big_enum_b));
+_Static_assert(GET_TYPE_INT(big_enum_a) == GET_TYPE_INT(big_enum_b), "ok");
diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index cdbe1e95cba965..6bcc41888a6343 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -88,4 +88,4 @@ CHECK-NEXT: warn_weak_import
The list of warnings in -Wpedantic should NEVER grow.
-CHECK: Number in -Wpedantic (not covered by other -W flags): 25
+CHECK: Number in -Wpedantic (not covered by other -W flags): 24
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index d2cd27a0c02299..b9183d3fb2b8c8 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -1,23 +1,23 @@
// RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify=expected,c99 -pedantic
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -fsyntax-only -std=c23 -verify -pedantic
enum e {A,
- B = 42LL << 32, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
+ B = 42LL << 32, // c99-warning {{enumerator values exceeding range of 'int' is a C23 extension}}
C = -4, D = 12456 };
enum f { a = -2147483648, b = 2147483647 }; // ok.
enum g { // too negative
- c = -2147483649, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
+ c = -2147483649, // c99-warning {{enumerator values exceeding range of 'int' is a C23 extension}}
d = 2147483647 };
enum h { e = -2147483648, // too pos
- f = 2147483648, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
+ f = 2147483648, // c99-warning {{enumerator values exceeding range of 'int' is a C23 extension}}
i = 0xFFFF0000 // c99-warning {{too large}}
};
// minll maxull
enum x // expected-warning {{enumeration values exceed range of largest integer}}
-{ y = -9223372036854775807LL-1, // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
-z = 9223372036854775808ULL }; // c99-warning {{ISO C restricts enumerator values to range of 'int'}}
+{ y = -9223372036854775807LL-1, // c99-warning {{enumerator values exceeding range of 'int' is a C23 extension}}
+z = 9223372036854775808ULL }; // c99-warning {{enumerator values exceeding range of 'int' is a C23 extension}}
int test(void) {
return sizeof(enum e) ;
More information about the cfe-commits
mailing list