[PATCH] D17444: PR26672: [MSVC] Clang does not recognize "static_assert" keyword in C mode

Andrey Bokhanko via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 20 04:53:53 PST 2016


andreybokhanko updated this revision to Diff 48591.
andreybokhanko added a comment.

Patch updated in response to Reid's proposal (to introduce KEYMSCOMPAT).

(To clarify, I agree with Aaron that we should wait for MS' response first. Though I frankly don't expect them to accept recognition of "static_assert" as a bug, so wanted to have a patch ready.)

Yours,

Andrey
======

Software Engineer
Intel Compiler Team


http://reviews.llvm.org/D17444

Files:
  include/clang/Basic/TokenKinds.def
  lib/Basic/IdentifierTable.cpp
  test/Lexer/keywords_test.cpp

Index: lib/Basic/IdentifierTable.cpp
===================================================================
--- lib/Basic/IdentifierTable.cpp
+++ lib/Basic/IdentifierTable.cpp
@@ -113,6 +113,7 @@
     KEYOBJC2    = 0x20000,
     KEYZVECTOR  = 0x40000,
     KEYCOROUTINES = 0x80000,
+    KEYMSCOMPAT = 0x100000,
     KEYALL = (0xfffff & ~KEYNOMS18 &
               ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
   };
@@ -136,6 +137,7 @@
   if (LangOpts.C99 && (Flags & KEYC99)) return KS_Enabled;
   if (LangOpts.GNUKeywords && (Flags & KEYGNU)) return KS_Extension;
   if (LangOpts.MicrosoftExt && (Flags & KEYMS)) return KS_Extension;
+  if (LangOpts.MSVCCompat && (Flags & KEYMSCOMPAT)) return KS_Enabled;
   if (LangOpts.Borland && (Flags & KEYBORLAND)) return KS_Extension;
   if (LangOpts.Bool && (Flags & BOOLSUPPORT)) return KS_Enabled;
   if (LangOpts.Half && (Flags & HALFSUPPORT)) return KS_Enabled;
Index: include/clang/Basic/TokenKinds.def
===================================================================
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -237,6 +237,7 @@
 //                 are enabled.
 //   KEYGNU   - This is a keyword if GNU extensions are enabled
 //   KEYMS    - This is a keyword if Microsoft extensions are enabled
+//   KEYMSCOMPAT - This is a keyword if Microsoft compatibility mode is enabled
 //   KEYNOMS18 - This is a keyword that must never be enabled under
 //               MSVC <= v18.
 //   KEYOPENCL  - This is a keyword in OpenCL
@@ -354,7 +355,7 @@
 CXX11_KEYWORD(decltype              , 0)
 CXX11_KEYWORD(noexcept              , 0)
 CXX11_KEYWORD(nullptr               , 0)
-CXX11_KEYWORD(static_assert         , 0)
+CXX11_KEYWORD(static_assert         , KEYMSCOMPAT)
 CXX11_KEYWORD(thread_local          , 0)
 
 // C++ concepts TS keywords
Index: test/Lexer/keywords_test.cpp
===================================================================
--- test/Lexer/keywords_test.cpp
+++ test/Lexer/keywords_test.cpp
@@ -10,9 +10,9 @@
 // RUN: %clang_cc1 -std=c++03 -fdeclspec -fno-declspec -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++03 -fms-extensions -fno-declspec -fdeclspec -DDECLSPEC -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++03 -fms-extensions -fdeclspec -fno-declspec -fsyntax-only %s
-// RUN: %clang -std=c++03 -target i686-windows-msvc -DDECLSPEC -fsyntax-only %s
+// RUN: %clang -std=c++03 -target i686-windows-msvc -DMS -DDECLSPEC -fsyntax-only %s
 // RUN: %clang -std=c++03 -target x86_64-scei-ps4 -DDECLSPEC -fsyntax-only %s
-// RUN: %clang -std=c++03 -target i686-windows-msvc -fno-declspec -fsyntax-only %s
+// RUN: %clang -std=c++03 -target i686-windows-msvc -DMS -fno-declspec -fsyntax-only %s
 // RUN: %clang -std=c++03 -target x86_64-scei-ps4 -fno-declspec -fsyntax-only %s
 
 #define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME)
@@ -50,7 +50,12 @@
 CXX11_TYPE(char32_t);
 CXX11_KEYWORD(constexpr);
 CXX11_KEYWORD(noexcept);
+#ifndef MS
 CXX11_KEYWORD(static_assert);
+#else
+// MS compiler recognizes static_assert in all modes. So should we.
+IS_KEYWORD(static_assert);
+#endif
 CXX11_KEYWORD(thread_local);
 
 // Concepts TS keywords


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17444.48591.patch
Type: text/x-patch
Size: 3175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160220/edf8c3de/attachment.bin>


More information about the cfe-commits mailing list