[clang] [clang] treat [[gnu::flag_enum]] as equivalent to [[clang::flag_enum]] (PR #219105)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 21:30:26 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Matthias Wippich (Tsche)

<details>
<summary>Changes</summary>

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]`.

---
Full diff: https://github.com/llvm/llvm-project/pull/219105.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+2) 
- (modified) clang/include/clang/Basic/Attr.td (+1-1) 
- (modified) clang/test/Sema/attr-c2x.c (+4) 


``````````diff
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);
 

``````````

</details>


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


More information about the cfe-commits mailing list