]> granicus.if.org Git - clang/commitdiff
Turns #import in MS Mode into an error.
authorAaron Ballman <aaron@aaronballman.com>
Sun, 18 Mar 2012 03:10:37 +0000 (03:10 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Sun, 18 Mar 2012 03:10:37 +0000 (03:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153009 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
include/clang/Lex/Preprocessor.h
lib/Lex/PPDirectives.cpp
test/Preprocessor/microsoft-import.c [new file with mode: 0644]

index becbd73198e2837e55092a979979be0a0a15c657..c6d26a069f8b34755646aa07ee6b5ab2f7cf07cf 100644 (file)
@@ -228,6 +228,10 @@ def warn_pp_convert_rhs_to_positive : Warning<
 
 def ext_pp_import_directive : Extension<"#import is a language extension">,
   InGroup<DiagGroup<"import-preprocessor-directive-pedantic">>;
+def err_pp_import_directive_ms : Error<
+  "#import of type library is an unsupported Microsoft feature">,
+  InGroup<Microsoft>;
+
 def ext_pp_ident_directive : Extension<"#ident is a language extension">;
 def ext_pp_include_next_directive : Extension<
   "#include_next is a language extension">;
index 2abf74ed0a0936b4c9c2c4f59ecc3d24c213ddb9..fa9c417af543764956fc61b4f1d5098a20f58761 100644 (file)
@@ -1250,6 +1250,7 @@ private:
   void HandleIncludeNextDirective(SourceLocation HashLoc, Token &Tok);
   void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
   void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
+  void HandleMicrosoftImportDirective(Token &Tok);
 
   // Macro handling.
   void HandleDefineDirective(Token &Tok);
index 53bb5c354e95e0920c4832f1b475ed5da4f3da85..3d96e86cb2d8ab51b3c3222d9ad23021f82a10e6 100644 (file)
@@ -1484,13 +1484,29 @@ void Preprocessor::HandleIncludeNextDirective(SourceLocation HashLoc,
   return HandleIncludeDirective(HashLoc, IncludeNextTok, Lookup);
 }
 
+/// HandleMicrosoftImportDirective - Implements #import for Microsoft Mode
+void Preprocessor::HandleMicrosoftImportDirective(Token &Tok) {
+  // The Microsoft #import directive takes a type library and generates header
+  // files from it, and includes those.  This is beyond the scope of what clang
+  // does, so we ignore it and error out.  However, #import can optionally have
+  // trailing attributes that span multiple lines.  We're going to eat those
+  // so we can continue processing from there.
+  Diag(Tok, diag::err_pp_import_directive_ms );
+
+  // Read tokens until we get to the end of the directive.  Note that the 
+  // directive can be split over multiple lines using the backslash character.
+  DiscardUntilEndOfDirective();
+}
+
 /// HandleImportDirective - Implements #import.
 ///
 void Preprocessor::HandleImportDirective(SourceLocation HashLoc,
                                          Token &ImportTok) {
-  if (!LangOpts.ObjC1)  // #import is standard for ObjC.
+  if (!LangOpts.ObjC1) {  // #import is standard for ObjC.
+    if (LangOpts.MicrosoftMode)
+      return HandleMicrosoftImportDirective(ImportTok);
     Diag(ImportTok, diag::ext_pp_import_directive);
-
+  }
   return HandleIncludeDirective(HashLoc, ImportTok, 0, true);
 }
 
diff --git a/test/Preprocessor/microsoft-import.c b/test/Preprocessor/microsoft-import.c
new file mode 100644 (file)
index 0000000..56b5286
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -E -fms-compatibility %s 2>&1 | grep 'doh.c:100:2: error: #import of type library is an unsupported Microsoft feature'\r
+// RUN: %clang_cc1 -E -fms-compatibility %s 2>&1 | grep 'doh.c:200:2: error: #import of type library is an unsupported Microsoft feature'\r
+// RUN: %clang_cc1 -E -fms-compatibility %s 2>&1 | grep 'doh.c:300:2: error: #import of type library is an unsupported Microsoft feature'\r
+
+#line 100 "doh.c"\r
+#import "pp-record.h" // expected-error {{#import of type library is an unsupported Microsoft feature}}
+
+// Test attributes
+#line 200 "doh.c"\r
+#import "pp-record.h" no_namespace, auto_rename // expected-error {{#import of type library is an unsupported Microsoft feature}}
+
+// This will also fire the "#import of type library is an unsupported Microsoft feature"
+// error, but we can't use -verify because there's no way to put the comment on the proper line\r
+#line 300 "doh.c"\r
+#import "pp-record.h" no_namespace \
+                      auto_rename \
+                      auto_search\r