]> granicus.if.org Git - clang/commitdiff
Treat the Microsoft/Borland keyword "__except" as a context-sensitive
authorDouglas Gregor <dgregor@apple.com>
Fri, 21 Oct 2011 03:57:52 +0000 (03:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 21 Oct 2011 03:57:52 +0000 (03:57 +0000)
keyword, because both libstdc++ and libc++ use "__except" as an
identifier. Fixes <rdar://problem/10322555>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142636 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TokenKinds.def
include/clang/Parse/Parser.h
lib/Parse/ParseStmt.cpp
lib/Parse/Parser.cpp
test/Sema/__try.c
test/SemaCXX/MicrosoftExtensions.cpp

index cd0cd06a61d8e99fff0175f3bb0084cbaa031c11..de345af7013551c308ef4da3f3f9f40a0fc05185 100644 (file)
@@ -485,7 +485,6 @@ KEYWORD(__ptr32                   , KEYMS)
 KEYWORD(__w64                     , KEYMS)
 KEYWORD(__uuidof                  , KEYMS | KEYBORLAND)
 KEYWORD(__try                     , KEYMS | KEYBORLAND)
-KEYWORD(__except                  , KEYMS | KEYBORLAND)
 KEYWORD(__finally                 , KEYMS | KEYBORLAND)
 KEYWORD(__leave                   , KEYMS | KEYBORLAND)
 KEYWORD(__int64                   , KEYMS)
index e28bcf2001ffdec4f3f19ae0c68c21acd06fba78..5cd6e44870855fba4f9754548bd99def3b53ae0e 100644 (file)
@@ -112,6 +112,9 @@ class Parser : public CodeCompletionHandler {
   IdentifierInfo *Ident__exception_info, *Ident___exception_info, *Ident_GetExceptionInfo; // __except filter expression
   IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination, *Ident_AbnormalTermination; // __finally
 
+  /// Contextual keywords for Microsoft extensions.
+  IdentifierInfo *Ident__except;
+  
   /// Ident_super - IdentifierInfo for "super", to support fast
   /// comparison.
   IdentifierInfo *Ident_super;
@@ -179,6 +182,8 @@ class Parser : public CodeCompletionHandler {
   /// declaration is finished.
   DelayedCleanupPool TopLevelDeclCleanupPool;
 
+  IdentifierInfo *getSEHExceptKeyword();
+  
 public:
   Parser(Preprocessor &PP, Sema &Actions);
   ~Parser();
index 3df761af44b28ec3fb0236dedae552f65b1c20f8..8968a4348022722944f064e72d041deecef529b6 100644 (file)
@@ -355,7 +355,8 @@ StmtResult Parser::ParseSEHTryBlockCommon(SourceLocation TryLoc) {
     return move(TryBlock);
 
   StmtResult Handler;
-  if(Tok.is(tok::kw___except)) {
+  if (Tok.is(tok::identifier) && 
+      Tok.getIdentifierInfo() == getSEHExceptKeyword()) {
     SourceLocation Loc = ConsumeToken();
     Handler = ParseSEHExceptBlock(Loc);
   } else if (Tok.is(tok::kw___finally)) {
@@ -2037,10 +2038,13 @@ StmtResult Parser::ParseCXXTryBlockCommon(SourceLocation TryLoc) {
     return move(TryBlock);
 
   // Borland allows SEH-handlers with 'try'
-  if(Tok.is(tok::kw___except) || Tok.is(tok::kw___finally)) {
+  
+  if((Tok.is(tok::identifier) && 
+      Tok.getIdentifierInfo() == getSEHExceptKeyword()) || 
+     Tok.is(tok::kw___finally)) {
     // TODO: Factor into common return ParseSEHHandlerCommon(...)
     StmtResult Handler;
-    if(Tok.is(tok::kw___except)) {
+    if(Tok.getIdentifierInfo() == getSEHExceptKeyword()) {
       SourceLocation Loc = ConsumeToken();
       Handler = ParseSEHExceptBlock(Loc);
     }
index 2e0c46dbdbfea63e9109756d5a0b102012f59f34..2face304c0a6f36e0751225d0fb59523d4b08f9c 100644 (file)
 #include "clang/AST/ASTConsumer.h"
 using namespace clang;
 
+IdentifierInfo *Parser::getSEHExceptKeyword() {
+  // __except is accepted as a (contextual) keyword 
+  if (!Ident__except && (getLang().MicrosoftExt || getLang().Borland))
+    Ident__except = PP.getIdentifierInfo("__except");
+
+  return Ident__except;
+}
+
 Parser::Parser(Preprocessor &pp, Sema &actions)
   : PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
     GreaterThanIsOperator(true), ColonIsSacred(false), 
@@ -431,6 +439,8 @@ void Parser::Initialize() {
   Ident_obsoleted = 0;
   Ident_unavailable = 0;
 
+  Ident__except = 0;
+  
   Ident__exception_code = Ident__exception_info = Ident__abnormal_termination = 0;
   Ident___exception_code = Ident___exception_info = Ident___abnormal_termination = 0;
   Ident_GetExceptionCode = Ident_GetExceptionInfo = Ident_AbnormalTermination = 0;
index 5490aea539edfc3b6fe3f8c8b76b172d8b94410b..1641402e7eae0ce4ab6859cb616a6d07bdeeb41c 100644 (file)
@@ -20,7 +20,7 @@ void __abnormal_termination();
 
 #pragma sysheader end
 
-DWORD FilterExpression(int);
+DWORD FilterExpression(int); // expected-note{{declared here}}
 DWORD FilterExceptionInformation(struct EXCEPTION_INFO*);
 
 const char * NotFilterExpression();
@@ -47,7 +47,8 @@ void TEST() {
 }  // expected-error{{expected '__except' or '__finally' block}}
 
 void TEST() {
-  __except ( FilterExpression() ) { // expected-error{{}}
+  __except ( FilterExpression() ) { // expected-warning{{implicit declaration of function '__except' is invalid in C99}} \
+    // expected-error{{too few arguments to function call, expected 1, have 0}}
 
   }
 }
index ddf5d9d6a186c7681d0e3f18c03286335ea874ee..62f4f61471807c279e1e705d063a1892c1f9a4ea 100644 (file)
@@ -210,3 +210,6 @@ struct PR11150 {
 
   int array[__is_abstract(X)? 1 : -1];
 };
+
+void f() { int __except = 0; }
+