[PATCH] D95559: clang: Fix static_assert in a few contexts in microsoft mode

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 27 13:52:54 PST 2021


thakis created this revision.
thakis added reviewers: hans, rnk.
thakis requested review of this revision.

Follow-up to D17444 <https://reviews.llvm.org/D17444>. Fixes PR48904. See bug for details.


https://reviews.llvm.org/D95559

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


Index: clang/test/Sema/static-assert.c
===================================================================
--- clang/test/Sema/static-assert.c
+++ 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(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 @@
   _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
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4216,7 +4216,7 @@
     }
 
     // Parse _Static_assert declaration.
-    if (Tok.is(tok::kw__Static_assert)) {
+    if (Tok.is(tok::kw__Static_assert) || Tok.is(tok::kw_static_assert)) {
       SourceLocation DeclEnd;
       ParseStaticAssertDeclaration(DeclEnd);
       continue;
@@ -5180,6 +5180,7 @@
   case tok::kw_friend:
 
     // static_assert-declaration
+  case tok::kw_static_assert:
   case tok::kw__Static_assert:
 
     // GNU typeof support.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95559.319661.patch
Type: text/x-patch
Size: 2249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210127/3b0ac6ff/attachment.bin>


More information about the cfe-commits mailing list