diff --git a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp --- a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp +++ b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp @@ -1,6 +1,6 @@ - -// This file intentionally uses a CRLF newlines! - -void foo() { - int *x = 0; -} + +// This file intentionally uses a CRLF newlines! + +void foo() { + int *x = 0; +} diff --git a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected --- a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected +++ b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected @@ -1,6 +1,6 @@ - -// This file intentionally uses a CRLF newlines! - -void foo() { - int *x = nullptr; -} + +// This file intentionally uses a CRLF newlines! + +void foo() { + int *x = nullptr; +} diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -427,6 +427,8 @@ def ext_pp_opencl_variadic_macros : Extension< "variadic macros are a Clang extension in OpenCL">; +def warn_pp_gnu_ext_line_directive : Warning<"style of line directive is a GNU extension">; + def err_pp_invalid_directive : Error<"invalid preprocessing directive">; def err_pp_directive_required : Error< "%0 must be used within a preprocessing directive">; diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1432,6 +1432,7 @@ // string followed by eod. if (StrTok.is(tok::eod)) { // Treat this like "#line NN", which doesn't change file characteristics. + Diag(StrTok, diag::warn_pp_gnu_ext_line_directive); FileKind = SourceMgr.getFileCharacteristic(DigitTok.getLocation()); } else if (StrTok.isNot(tok::string_literal)) { Diag(StrTok, diag::err_pp_linemarker_invalid_filename); diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c --- a/clang/test/Misc/warning-flags.c +++ b/clang/test/Misc/warning-flags.c @@ -18,7 +18,7 @@ The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (67): +CHECK: Warnings without flags (68): CHECK-NEXT: ext_expected_semi_decl_list CHECK-NEXT: ext_explicit_specialization_storage_class @@ -71,6 +71,7 @@ CHECK-NEXT: warn_on_superclass_use CHECK-NEXT: warn_pp_convert_to_positive CHECK-NEXT: warn_pp_expr_overflow +CHECK-NEXT: warn_pp_gnu_ext_line_directive CHECK-NEXT: warn_pp_line_decimal CHECK-NEXT: warn_pragma_pack_pop_identifier_and_alignment CHECK-NEXT: warn_pragma_pack_show diff --git a/clang/test/Preprocessor/line-directive.c b/clang/test/Preprocessor/line-directive.c --- a/clang/test/Preprocessor/line-directive.c +++ b/clang/test/Preprocessor/line-directive.c @@ -27,7 +27,7 @@ #define A 42 "foo" #line A -# 42 +# 42 // expected-warning {{style of line directive is a GNU extension}} # 42 "foo" # 42 "foo" 2 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}} # 42 "foo" 1 3 // enter @@ -97,7 +97,7 @@ #line 010 // expected-warning {{#line directive interprets number as decimal, not octal}} extern int array[__LINE__ == 10 ? 1:-1]; -# 020 // expected-warning {{GNU line marker directive interprets number as decimal, not octal}} +# 020 // expected-warning {{GNU line marker directive interprets number as decimal, not octal}} expected-warning {{style of line directive is a GNU extension}} extern int array_gnuline[__LINE__ == 20 ? 1:-1]; /* PR3917 */ @@ -106,7 +106,7 @@ _\ _LINE__ == 42 ? 1: -1]; /* line marker is location of first _ */ -# 51 +# 51 // expected-warning {{style of line directive is a GNU extension}} extern char array2_gnuline[\ _\ _LINE__ == 52 ? 1: -1]; /* line marker is location of first _ */ diff --git a/clang/test/Preprocessor/warn-gnu-ext-line-directive.c b/clang/test/Preprocessor/warn-gnu-ext-line-directive.c new file mode 100644 --- /dev/null +++ b/clang/test/Preprocessor/warn-gnu-ext-line-directive.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify + +#1 // expected-warning {{style of line directive is a GNU extension}}