[cfe-commits] [patch] _Bool in yvals.h

Douglas Gregor dgregor at apple.com
Thu May 20 12:51:46 PDT 2010


On May 20, 2010, at 10:25 AM, Steven Watanabe wrote:

> AMDG
> 
> The attached patch deals with the fact the yvals.h
> in the standard library that ships with msvc contains
> typedef bool _Bool;
> However, i'd really prefer to disable the _Bool keyword
> in Microsoft compatibility mode.  Is there a good
> way to do this?


It should be easy to do directly. Check check out include/clang/TokenKinds.def and its uses; the _Bool keyword could probably be tagged with some new flag (e.g., KEYNOMS) that enables it unless -fms-extensions is provided.

Index: tools/clang/lib/Parse/ParseDecl.cpp
===================================================================
--- tools/clang/lib/Parse/ParseDecl.cpp	(revision 104222)
+++ tools/clang/lib/Parse/ParseDecl.cpp	(working copy)
@@ -1276,8 +1276,18 @@
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec,
                                     DiagID);
      break;
+    case tok::kw__Bool:
+      // Microsoft has a typedef bool _Bool;  As a totally
+      // evil hack, if we see this construct, stop treating
+      // _Bool as a keyword
+      if(DS.getTypeSpecType() == DeclSpec::TST_bool) {
+          IdentifierTable& table = PP.getIdentifierTable();
+          IdentifierInfo& ident = table.get(llvm::StringRef("_Bool"));
+          ident.setTokenID(tok::identifier);
+          Tok.setKind(tok::identifier);
+          goto DoneWithDeclSpec;
+      }

It would be much better just to make sure that _Bool isn't a keyword in -fms-extensions mode.

	- Doug



More information about the cfe-commits mailing list