Emit a -Wmicrosoft warning when treating ^Z as EOF in MS mode.

llvm-svn: 256596
This commit is contained in:
Nico Weber 2015-12-29 23:17:27 +00:00
parent 446cf25c21
commit de2310bddf
4 changed files with 11 additions and 4 deletions

View File

@ -766,6 +766,7 @@ def MicrosoftConstInit : DiagGroup<"microsoft-const-init">;
def MicrosoftVoidPseudoDtor : DiagGroup<"microsoft-void-pseudo-dtor">;
def MicrosoftAnonTag : DiagGroup<"microsoft-anon-tag">;
def MicrosoftCommentPaste : DiagGroup<"microsoft-comment-paste">;
def MicrosoftEndOfFile : DiagGroup<"microsoft-end-of-file">;
// Aliases.
def : DiagGroup<"msvc-include", [MicrosoftInclude]>;
// -Wmsvc-include = -Wmicrosoft-include
@ -780,7 +781,7 @@ def Microsoft : DiagGroup<"microsoft",
MicrosoftRedeclareStatic, MicrosoftEnumForwardReference, MicrosoftGoto,
MicrosoftFlexibleArray, MicrosoftExtraQualification, MicrosoftCast,
MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag,
MicrosoftCommentPaste]>;
MicrosoftCommentPaste, MicrosoftEndOfFile]>;
def ObjCNonUnifiedException : DiagGroup<"objc-nonunified-exceptions">;

View File

@ -62,6 +62,9 @@ def ext_charize_microsoft : Extension<
def ext_comment_paste_microsoft : Extension<
"pasting two '/' tokens into a '//' comment token is a Microsoft extension">,
InGroup<MicrosoftCommentPaste>;
def ext_ctrl_z_eof_microsoft : Extension<
"treating Ctrl-Z as end-of-file is a Microsoft extension">,
InGroup<MicrosoftEndOfFile>;
def ext_token_used : Extension<"extension used">,
InGroup<DiagGroup<"language-extension-token">>;

View File

@ -2960,8 +2960,11 @@ LexNextToken:
case 26: // DOS & CP/M EOF: "^Z".
// If we're in Microsoft extensions mode, treat this as end of file.
if (LangOpts.MicrosoftExt)
if (LangOpts.MicrosoftExt) {
if (!isLexingRawMode())
Diag(CurPtr-1, diag::ext_ctrl_z_eof_microsoft);
return LexEndOfFile(Result, CurPtr-1);
}
// If Microsoft extensions are disabled, this is just random garbage.
Kind = tok::unknown;

View File

@ -1,8 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s
// expected-no-diagnostics
// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions -Wmicrosoft %s
int x;
// expected-warning@+1 {{treating Ctrl-Z as end-of-file is a Microsoft extension">,

I am random garbage after ^Z