From cfbe5d01ee1fbd7c9c63d0d321acc789902fbd0d Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Wed, 18 Dec 2013 14:53:36 +0000 Subject: gcc: add Apple compatible -Wnewline-eof GCC 4.2 and previous have always warned about "No newline at end of file". Upstream GCC removed the warning completely but Apple made it an optional warning. Adopt it for compatibility with older GCC and clang. While here, add comment to complement r258712. Obtained from: Apple Inc. (Apple GCC 4.2 - 5531) MFC after: 1 week --- contrib/gcc/c-opts.c | 6 ++++++ contrib/gcc/c.opt | 6 ++++++ contrib/gcc/doc/invoke.texi | 8 ++++++++ contrib/gcclibs/libcpp/ChangeLog.apple | 9 +++++++++ contrib/gcclibs/libcpp/charset.c | 1 + contrib/gcclibs/libcpp/include/cpplib.h | 5 +++++ contrib/gcclibs/libcpp/init.c | 4 ++++ contrib/gcclibs/libcpp/lex.c | 8 ++++++++ 8 files changed, 47 insertions(+) create mode 100644 contrib/gcclibs/libcpp/ChangeLog.apple (limited to 'contrib') diff --git a/contrib/gcc/c-opts.c b/contrib/gcc/c-opts.c index ed6b7718ecb5..6b290687c76d 100644 --- a/contrib/gcc/c-opts.c +++ b/contrib/gcc/c-opts.c @@ -487,6 +487,12 @@ c_common_handle_option (size_t scode, const char *arg, int value) cpp_opts->warn_multichar = value; break; + /* APPLE LOCAL begin -Wnewline-eof */ + case OPT_Wnewline_eof: + cpp_opts->warn_newline_at_eof = value; + break; + /* APPLE LOCAL end -Wnewline-eof */ + case OPT_Wnormalized_: if (!value || (arg && strcasecmp (arg, "none") == 0)) cpp_opts->warn_normalize = normalized_none; diff --git a/contrib/gcc/c.opt b/contrib/gcc/c.opt index 86e9460a7f71..58d13e8a7d65 100644 --- a/contrib/gcc/c.opt +++ b/contrib/gcc/c.opt @@ -292,6 +292,12 @@ Wnested-externs C ObjC Var(warn_nested_externs) Warn about \"extern\" declarations not at file scope +; APPLE LOCAL begin -Wnewline-eof +Wnewline-eof +C ObjC C++ ObjC++ +Warn about files missing a newline at the end of the file +; APPLE LOCAL end -Wnewline-eof + Wnon-template-friend C++ ObjC++ Var(warn_nontemplate_friend) Init(1) Warn when non-templatized friend functions are declared within a template diff --git a/contrib/gcc/doc/invoke.texi b/contrib/gcc/doc/invoke.texi index 5263e915c336..ed42d6f58a64 100644 --- a/contrib/gcc/doc/invoke.texi +++ b/contrib/gcc/doc/invoke.texi @@ -169,6 +169,8 @@ in the following sections. -trigraphs -no-integrated-cpp -traditional -traditional-cpp @gol -fallow-single-precision -fcond-mismatch -flax-vector-conversions @gol -fsigned-bitfields -fsigned-char @gol +@c APPLE LOCAL -Wnewline-eof 2001-08-23 --sts ** +-Wnewline-eof (Apple compatible) @gol -funsigned-bitfields -funsigned-char} @item C++ Language Options @@ -2082,6 +2084,12 @@ Inhibit all warning messages. @opindex Wno-import Inhibit warning messages about the use of @samp{#import}. +@c APPLE LOCAL begin -Wnewline-eof 2001-08-23 --sts ** +@item -Wnewline-eof +@opindex Wnewline-eof +Warn about files missing a newline at the end of the file. (FreeBSD ONLY) +@c APPLE LOCAL end -Wnewline-eof 2001-08-23 --sts ** + @item -Wchar-subscripts @opindex Wchar-subscripts Warn if an array subscript has type @code{char}. This is a common cause diff --git a/contrib/gcclibs/libcpp/ChangeLog.apple b/contrib/gcclibs/libcpp/ChangeLog.apple new file mode 100644 index 000000000000..c38bfe23324a --- /dev/null +++ b/contrib/gcclibs/libcpp/ChangeLog.apple @@ -0,0 +1,9 @@ +2008-08-04 Bill Wendling + + Radar 6121572 + * charset.c (_cpp_convert_input): Don't read to.text[-1]. + +2005-02-17 Devang Patel + + Radar 3958387 + * libcpp/lex.c (_cpp_get_fresh_line): Check warn_newline_at_eof. diff --git a/contrib/gcclibs/libcpp/charset.c b/contrib/gcclibs/libcpp/charset.c index 6361f8c51321..009106b06761 100644 --- a/contrib/gcclibs/libcpp/charset.c +++ b/contrib/gcclibs/libcpp/charset.c @@ -1628,6 +1628,7 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset, terminate with another \r, not an \n, so that we do not mistake the \r\n sequence for a single DOS line ending and erroneously issue the "No newline at end of file" diagnostic. */ + /* APPLE LOCAL don't access to.text[-1] radar 6121572 */ if (to.len > 0 && to.text[to.len - 1] == '\r') to.text[to.len] = '\r'; else diff --git a/contrib/gcclibs/libcpp/include/cpplib.h b/contrib/gcclibs/libcpp/include/cpplib.h index 5acef415c3d7..ac596d678bec 100644 --- a/contrib/gcclibs/libcpp/include/cpplib.h +++ b/contrib/gcclibs/libcpp/include/cpplib.h @@ -320,6 +320,11 @@ struct cpp_options /* Nonzero means warn if there are any trigraphs. */ unsigned char warn_trigraphs; + /* APPLE LOCAL begin -Wnewline-eof 2001-08-23 --sts */ + /* Nonzero means warn if no newline at end of file. */ + unsigned char warn_newline_at_eof; + /* APPLE LOCAL end -Wnewline-eof 2001-08-23 --sts */ + /* Nonzero means warn about multicharacter charconsts. */ unsigned char warn_multichar; diff --git a/contrib/gcclibs/libcpp/init.c b/contrib/gcclibs/libcpp/init.c index 248d84f53b75..9620676a6083 100644 --- a/contrib/gcclibs/libcpp/init.c +++ b/contrib/gcclibs/libcpp/init.c @@ -146,6 +146,10 @@ cpp_create_reader (enum c_lang lang, hash_table *table, pfile = XCNEW (cpp_reader); cpp_set_lang (pfile, lang); + /* APPLE LOCAL begin -Wnewline-eof 2001-08-23 --sts */ + /* Suppress warnings about missing newlines at ends of files. */ + CPP_OPTION (pfile, warn_newline_at_eof) = 0; + /* APPLE LOCAL end -Wnewline-eof 2001-08-23 --sts */ CPP_OPTION (pfile, warn_multichar) = 1; CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1; diff --git a/contrib/gcclibs/libcpp/lex.c b/contrib/gcclibs/libcpp/lex.c index ef59f900c64a..1a3cad7efd83 100644 --- a/contrib/gcclibs/libcpp/lex.c +++ b/contrib/gcclibs/libcpp/lex.c @@ -854,6 +854,14 @@ _cpp_get_fresh_line (cpp_reader *pfile) { /* Clip to buffer size. */ buffer->next_line = buffer->rlimit; + /* APPLE LOCAL begin suppress no newline warning. */ + if ( CPP_OPTION (pfile, warn_newline_at_eof)) + { + cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line_table->highest_line, + CPP_BUF_COLUMN (buffer, buffer->cur), + "no newline at end of file"); + } + /* APPLE LOCAL end suppress no newline warning. */ } return_at_eof = buffer->return_at_eof; -- cgit v1.2.3