This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Mac line ending at EOF AND no newline warnings



On Feb 17, 2005, at 4:15 PM, Zack Weinberg wrote:


Devang Patel <dpatel@apple.com> writes:
GCC emits no-newline warning when it sees Mac line ending
at the end of file. This is because _cpp_convert_input()
automatically inserts '\n' at the end of buffer. This
confuses _cpp_clean_line() when it sees '\r' and '\n' together.
I would rather this was dealt with in _cpp_convert_input - have it
check for a \r at EOF and not stick in an extra \n in that case.


I bootstrapped and tested following patch overnight. OK for mainline?

(I just noticed that I tested apple-ppc-branch. If approved, I'll
 test it again on mainline before commit).

Thanks,
-
Devang

2004-02-18 Devang Patel <dpatel@apple.com>

* libcpp/charset.c (_cpp_convert_input): Check '\r' before inserting
'\n' at the end.


* gcc.dg/cpp/Wmac-eol-at-eof.c: New test.


Index: libcpp/charset.c =================================================================== RCS file: /cvs/gcc/gcc/libcpp/charset.c,v retrieving revision 1.2.2.3 diff -Idpatel.pbxuser -c -3 -p -r1.2.2.3 charset.c *** libcpp/charset.c 15 Oct 2004 21:05:48 -0000 1.2.2.3 --- libcpp/charset.c 18 Feb 2005 19:14:48 -0000 *************** _cpp_convert_input (cpp_reader *pfile, c *** 1433,1439 **** if (to.len + 4096 < to.asize || to.len >= to.asize) to.text = xrealloc (to.text, to.len + 1);

!   to.text[to.len] = '\n';
    *st_size = to.len;
    return to.text;
  }
--- 1433,1441 ----
    if (to.len + 4096 < to.asize || to.len >= to.asize)
      to.text = xrealloc (to.text, to.len + 1);

!   if (to.text[to.len - 1] != '\r')
!     to.text[to.len] = '\n';
!
    *st_size = to.len;
    return to.text;
  }


0000000 / * T e s t n o n e w l i 0000020 n e a t e o f w a r n i n 0000040 g . * / \r / * { d g - d 0000060 o c o m p i l e } * / \r i 0000100 n t m a i n ( ) { r e t u 0000120 r n 0 ; } \r 0000131


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]