https://github.com/yicuixi updated https://github.com/llvm/llvm-project/pull/159981
>From 77fc06c7147e8eec1712f2c8babdb6fd8a48dd94 Mon Sep 17 00:00:00 2001 From: yicuixi <[email protected]> Date: Sun, 21 Sep 2025 22:22:28 +0800 Subject: [PATCH 1/2] [clang] Accept empty enum in MSVC compatible C Signed-off-by: yicuixi <[email protected]> --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDecl.cpp | 3 ++- clang/test/Parser/ms-empty-enum.c | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 clang/test/Parser/ms-empty-enum.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 46d56bb3f07f5..c4b5e15b2b4f9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -366,6 +366,7 @@ Bug Fixes in This Version - Fixed an assertion when an improper use of the ``malloc`` attribute targeting a function without arguments caused us to try to access a non-existent argument. (#GH159080) +- Accept empty enum in MSVC-compatible C. (#GH114402) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 22c01c4e371f3..17e29b3efc348 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5360,7 +5360,8 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl, T.consumeOpen(); // C does not allow an empty enumerator-list, C++ does [dcl.enum]. - if (Tok.is(tok::r_brace) && !getLangOpts().CPlusPlus) + if (Tok.is(tok::r_brace) && !getLangOpts().CPlusPlus && + !getLangOpts().MSVCCompat && !getLangOpts().MicrosoftExt) Diag(Tok, diag::err_empty_enum); SmallVector<Decl *, 32> EnumConstantDecls; diff --git a/clang/test/Parser/ms-empty-enum.c b/clang/test/Parser/ms-empty-enum.c new file mode 100644 index 0000000000000..37e34d7c154bf --- /dev/null +++ b/clang/test/Parser/ms-empty-enum.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions +// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-compatibility +// expected-no-diagnostics + +typedef enum tag1 { } A; +typedef enum tag2 { } B; +typedef enum : unsigned { } C; + >From 191eacf08e22c443bd1b091fc97d4a3ca13d9cee Mon Sep 17 00:00:00 2001 From: yicuixi <[email protected]> Date: Sun, 21 Sep 2025 23:17:18 +0800 Subject: [PATCH 2/2] Fix test Signed-off-by: yicuixi <[email protected]> --- clang/test/Parser/ms-empty-enum.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/test/Parser/ms-empty-enum.c b/clang/test/Parser/ms-empty-enum.c index 37e34d7c154bf..7508f7fd0d0d8 100644 --- a/clang/test/Parser/ms-empty-enum.c +++ b/clang/test/Parser/ms-empty-enum.c @@ -1,8 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions // RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-compatibility -// expected-no-diagnostics typedef enum tag1 { } A; typedef enum tag2 { } B; -typedef enum : unsigned { } C; +typedef enum : unsigned { } C; // expected-warning {{enumeration types with a fixed underlying type are a Microsoft extension}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
