diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 32353b51ee58..8e5f57d6d890 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -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">; diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 2ed40c0cdedd..bf86b7077cbb 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -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; +def ext_ctrl_z_eof_microsoft : Extension< + "treating Ctrl-Z as end-of-file is a Microsoft extension">, + InGroup; def ext_token_used : Extension<"extension used">, InGroup>; diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 4872dee82456..27b0feb48270 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -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; diff --git a/clang/test/Lexer/msdos-cpm-eof.c b/clang/test/Lexer/msdos-cpm-eof.c index 3469b59d4089..274e6305a91e 100644 --- a/clang/test/Lexer/msdos-cpm-eof.c +++ b/clang/test/Lexer/msdos-cpm-eof.c @@ -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