[clang] 764a7a2 - clang: Fix static_assert in a few contexts in microsoft mode

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 27 15:15:56 PST 2021


Author: Nico Weber
Date: 2021-01-27T18:15:25-05:00
New Revision: 764a7a2155c6747ec8d0b38d8edbb65960eae874

URL: https://github.com/llvm/llvm-project/commit/764a7a2155c6747ec8d0b38d8edbb65960eae874
DIFF: https://github.com/llvm/llvm-project/commit/764a7a2155c6747ec8d0b38d8edbb65960eae874.diff

LOG: clang: Fix static_assert in a few contexts in microsoft mode

Follow-up to D17444. Fixes PR48904. See bug for details.

Differential Revision: https://reviews.llvm.org/D95559

Added: 
    

Modified: 
    clang/lib/Parse/ParseDecl.cpp
    clang/test/Sema/static-assert.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 6a0ba519d56a..55a0c6a082aa 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4231,7 +4231,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
     }
 
     // Parse _Static_assert declaration.
-    if (Tok.is(tok::kw__Static_assert)) {
+    if (Tok.isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
       SourceLocation DeclEnd;
       ParseStaticAssertDeclaration(DeclEnd);
       continue;
@@ -5191,6 +5191,7 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
   case tok::kw_friend:
 
     // static_assert-declaration
+  case tok::kw_static_assert:
   case tok::kw__Static_assert:
 
     // GNU typeof support.

diff  --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index f08e557fc8ea..9105f2366985 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fms-compatibility -DMS -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s
 // RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext,cxx %s
 
@@ -11,10 +12,17 @@ _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 ex
 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
                                    // ext-warning {{'_Static_assert' is a C11 extension}}
 
+#ifdef MS
+static_assert(1, "1 is nonzero");
+#endif
+
 void foo(void) {
   _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
   _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
                                      // ext-warning {{'_Static_assert' is a C11 extension}}
+#ifdef MS
+  static_assert(1, "1 is nonzero");
+#endif
 }
 
 _Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}} \
@@ -25,6 +33,9 @@ struct A {
   _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
   _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
                                      // ext-warning {{'_Static_assert' is a C11 extension}}
+#ifdef MS
+  static_assert(1, "1 is nonzero");
+#endif
 };
 
 #ifdef __cplusplus


        


More information about the cfe-commits mailing list