https://github.com/Tsche created 
https://github.com/llvm/llvm-project/pull/219105

GCC gained a `[[gnu::flag_enum]]` attribute for consistency with clang in GCC 
15. With this patch, the `[[gnu::flag_enum]]` is recognized and handled 
equivalently to `[[clang::flag_enum]]`.

The patch introducing `[[gnu::flag_enum]]` in GCC is 
https://github.com/gcc-mirror/gcc/commit/1914ca8791ce4e0ba821e818cb6f86c76afdb6f2.
 GCC treats `[[clang::flag_enum]]` as equivalent to `[[gnu::flag_enum]`.

>From 25cae9f959c098336ab7f6ce9c49a9ee820fd4fe Mon Sep 17 00:00:00 2001
From: Matthias Wippich <[email protected]>
Date: Thu, 27 Aug 2026 05:54:41 +0200
Subject: [PATCH] [clang] treat [[gnu::flag_enum]] as equivalent to
 [[clang::flag_enum]]

---
 clang/docs/ReleaseNotes.md        | 2 ++
 clang/include/clang/Basic/Attr.td | 2 +-
 clang/test/Sema/attr-c2x.c        | 4 ++++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index cd7f40aec112d..c62653d3d3f78 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -234,6 +234,8 @@ features cannot lower the translation-unit ABI level;
 
 - Clang now properly propagates attributes on class and variable templates to 
their redeclarations, which will result in redeclarations not interfering with 
diagnostics. (#GH209812)
 
+- Clang now recognizes the `[[gnu::flag_enum]]` attribute and treats it 
equivalent to `[[clang::flag_enum]]`
+
 ### Improvements to Clang's diagnostics
 
 - More consistent rendering of Unicode characters in diagnostic messages.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 252b53e25e5c8..181eee2b066c8 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1994,7 +1994,7 @@ def MinSize : InheritableAttr {
 }
 
 def FlagEnum : InheritableAttr {
-  let Spellings = [Clang<"flag_enum">];
+  let Spellings = [ClangGCC<"flag_enum">];
   let Subjects = SubjectList<[Enum]>;
   let Documentation = [FlagEnumDocs];
   let SimpleHandler = 1;
diff --git a/clang/test/Sema/attr-c2x.c b/clang/test/Sema/attr-c2x.c
index eff90d639c0c0..017db3bee7a21 100644
--- a/clang/test/Sema/attr-c2x.c
+++ b/clang/test/Sema/attr-c2x.c
@@ -11,6 +11,10 @@ enum [[clang::flag_enum]] EnumFlag {
   D0 = 1, D1 = 8
 };
 
+enum [[gnu::flag_enum]] EnumFlag2 {
+  E0 = 1, E1 = 8
+};
+
 [[clang::overloadable]] void foo(void *c);
 [[clang::overloadable]] void foo(char *c);
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to