From 34cf330fae5b6d3bca48e1fadf7b7ad4ec47c80d Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 22 Mar 2002 22:29:07 +0000 Subject: [PATCH] * cpphash.h (struct cpp_reader): Remove mls_line and mls_col. * cpplex.c (unterminated): Delete. (parse_string): No string literal may extend over multiple lines. Suppress the error when preprocessing assembly. * cppmain.c (scan_translation_unit): Strings are single-line. * doc/cpp.texi: Update to match. * testsuite/gcc.dg/cpp/multiline.c: Update to match. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51195 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 10 ++++++ gcc/cpphash.h | 5 --- gcc/cpplex.c | 69 ++++++------------------------------ gcc/cppmain.c | 3 +- gcc/doc/cpp.texi | 51 ++++++++------------------ gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/cpp/multiline.c | 10 ++++-- 7 files changed, 49 insertions(+), 103 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c94dbdd..984e498 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2002-03-22 Neil Booth + + * cpphash.h (struct cpp_reader): Remove mls_line and mls_col. + * cpplex.c (unterminated): Delete. + (parse_string): No string literal may extend over multiple + lines. Suppress the error when preprocessing assembly. + * cppmain.c (scan_translation_unit): Strings are single-line. + + * doc/cpp.texi: Update to match. + 2002-03-22 Jakub Jelinek PR optimization/5854 diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 03de93f..3112bdb 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -266,11 +266,6 @@ struct cpp_reader /* Error counter for exit code. */ unsigned int errors; - /* Line and column where a newline was first seen in a string - constant (multi-line strings). */ - unsigned int mls_line; - unsigned int mls_col; - /* Buffer to hold macro definition string. */ unsigned char *macro_buffer; unsigned int macro_buffer_len; diff --git a/gcc/cpplex.c b/gcc/cpplex.c index a66c36a..a765967 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -82,7 +82,6 @@ static U_CHAR *parse_slow PARAMS ((cpp_reader *, const U_CHAR *, int, static void parse_number PARAMS ((cpp_reader *, cpp_string *, int)); static int unescaped_terminator_p PARAMS ((cpp_reader *, const U_CHAR *)); static void parse_string PARAMS ((cpp_reader *, cpp_token *, cppchar_t)); -static void unterminated PARAMS ((cpp_reader *, int)); static bool trigraph_p PARAMS ((cpp_reader *)); static void save_comment PARAMS ((cpp_reader *, cpp_token *, const U_CHAR *)); static int name_p PARAMS ((cpp_reader *, const cpp_string *)); @@ -575,22 +574,6 @@ parse_number (pfile, number, leading_period) } } -/* Subroutine of parse_string. Emits error for unterminated strings. */ -static void -unterminated (pfile, term) - cpp_reader *pfile; - int term; -{ - cpp_error (pfile, "missing terminating %c character", term); - - if (term == '\"' && pfile->mls_line && pfile->mls_line != pfile->line) - { - cpp_error_with_line (pfile, pfile->mls_line, pfile->mls_col, - "possible start of unterminated string literal"); - pfile->mls_line = 0; - } -} - /* Subroutine of parse_string. */ static int unescaped_terminator_p (pfile, dest) @@ -617,7 +600,6 @@ unescaped_terminator_p (pfile, dest) name. Handles embedded trigraphs and escaped newlines. The stored string is guaranteed NUL-terminated, but it is not guaranteed that this is the first NUL since embedded NULs are preserved. - Multi-line strings are allowed, but they are deprecated. When this function returns, buffer->cur points to the next character to be processed. */ @@ -630,7 +612,7 @@ parse_string (pfile, token, terminator) cpp_buffer *buffer = pfile->buffer; unsigned char *dest, *limit; cppchar_t c; - bool warned_nulls = false, warned_multi = false; + bool warned_nulls = false; dest = BUFF_FRONT (pfile->u_buff); limit = BUFF_LIMIT (pfile->u_buff); @@ -658,49 +640,20 @@ parse_string (pfile, token, terminator) } else if (is_vspace (c)) { - /* In assembly language, silently terminate string and - character literals at end of line. This is a kludge - around not knowing where comments are. */ - if (CPP_OPTION (pfile, lang) == CLK_ASM && terminator != '>') - { - buffer->cur--; - break; - } - - /* Character constants and header names may not extend over - multiple lines. In Standard C, neither may strings. - Unfortunately, we accept multiline strings as an - extension, except in #include family directives. */ - if (terminator != '"' || pfile->state.angled_headers) - { - unterminated (pfile, terminator); - buffer->cur--; - break; - } - - if (!warned_multi) - { - warned_multi = true; - cpp_pedwarn (pfile, "multi-line string literals are deprecated"); - } - - if (pfile->mls_line == 0) - { - pfile->mls_line = token->line; - pfile->mls_col = token->col; - } - - handle_newline (pfile); - c = '\n'; + /* No string literal may extend over multiple lines. In + assembly language, suppress the error except for <> + includes. This is a kludge around not knowing where + comments are. */ + unterminated: + if (CPP_OPTION (pfile, lang) != CLK_ASM || terminator == '>') + cpp_error (pfile, "missing terminating %c character", terminator); + buffer->cur--; + break; } else if (c == '\0') { if (buffer->cur - 1 == buffer->rlimit) - { - unterminated (pfile, terminator); - buffer->cur--; - break; - } + goto unterminated; if (!warned_nulls) { warned_nulls = true; diff --git a/gcc/cppmain.c b/gcc/cppmain.c index b8757c7..99ca2de 100644 --- a/gcc/cppmain.c +++ b/gcc/cppmain.c @@ -259,8 +259,7 @@ scan_translation_unit (pfile) print.prev = token; cpp_output_token (token, print.outf); - if (token->type == CPP_STRING || token->type == CPP_WSTRING - || token->type == CPP_COMMENT) + if (token->type == CPP_COMMENT) check_multiline_token (&token->val.str); } } diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index 3087e35..77745e7 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -402,26 +402,8 @@ extremely confusing and should not be used in code intended to be readable. There is no way to prevent a backslash at the end of a line from being -interpreted as a backslash-newline. - -@example -"foo\\ -bar" -@end example - -@noindent -is equivalent to @code{"foo\bar"}, not to @code{"foo\\bar"}. To avoid -having to worry about this, do not use the deprecated GNU extension -which permits multi-line strings. Instead, use string literal -concatenation: - -@example - "foo\\" - "bar" -@end example - -@noindent -Your program will be more portable this way, too. +interpreted as a backslash-newline. This cannot affect any correct +program, however. @node Tokenization @section Tokenization @@ -536,11 +518,10 @@ closing quote or angle bracket. The preprocessor looks for the header file in different places depending on which form you use. @xref{Include Operation}. -In standard C, no string literal may extend past the end of a line. GNU -CPP accepts multi-line string constants, but not multi-line character -constants or header file names. This extension is deprecated and will -be removed in GCC 3.1. You may use continued lines instead, or string -constant concatenation. @xref{Differences from previous versions}. +No string literal may extend past the end of a line. Older versions +of GCC accepted multi-line string constants. You may use continued +lines instead, or string constant concatenation. @xref{Differences +from previous versions}. @cindex punctuators @cindex digraphs @@ -796,10 +777,10 @@ those are merely the typical uses. Any fragment of a C program can be included from another file. The include file could even contain the beginning of a statement that is concluded in the containing file, or the end of a statement that was started in the including file. However, -a comment or a string or character constant may not start in the -included file and finish in the including file. An unterminated -comment, string constant or character constant in an included file is -considered to end (with an error message) at the end of the file. +an included file must consist of complete tokens. Comments and string +literals which have not been closed by the end of an included file are +invalid. For error recovery, they are considered to end at the end of +the file. To avoid confusion, it is best if header files contain only complete syntactic units---function declarations or definitions, type @@ -3785,13 +3766,11 @@ This is the same as @code{#pragma GCC poison}. The version without the @cindex multi-line string constants @item Multi-line string constants -GCC currently allows a string constant to extend across multiple logical -lines of the source file. This extension is deprecated and will be -removed in a future version of GCC@. Such string constants are already -rejected in all directives apart from @samp{#define}. - -Instead, make use of ISO C concatenation of adjacent string literals, or -use @samp{\n} followed by a backslash-newline. +Older versions of GCC allowed string constants to extend across +multiple logical lines of the source file. This ill-considered +extension has now been removed. Instead, make use of ISO C +concatenation of adjacent string literals, or use @samp{\n} followed +by a backslash-newline. @end itemize diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 627c1c8..a2545b6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-03-22 Neil Booth + + * gcc.dg/cpp/multiline.c: Update to match. + 2002-03-22 Alexandre Oliva * g++.old-deja/g++.abi/ptrmem.C: Mips puts vbit in delta too. diff --git a/gcc/testsuite/gcc.dg/cpp/multiline.c b/gcc/testsuite/gcc.dg/cpp/multiline.c index 1db0a3e..efd2b6d 100644 --- a/gcc/testsuite/gcc.dg/cpp/multiline.c +++ b/gcc/testsuite/gcc.dg/cpp/multiline.c @@ -22,5 +22,11 @@ L"line 1 { dg-final { if \{ [grep multiline.i "^$"] == "" \} \{ } } { dg-final { return \} } } { dg-final { fail "multiline.c: multi-line tokens" } } */ -/* { dg-warning "deprecated" "multiline strings" { target *-*-* } 11 } */ -/* { dg-warning "deprecated" "multiline strings" { target *-*-* } 15 } */ +/* { dg-error "missing term" "multiline strings" { target *-*-* } 11 } */ +/* { dg-error "missing term" "multiline strings" { target *-*-* } 14 } */ +/* { dg-error "missing term" "multiline strings" { target *-*-* } 15 } */ +/* { dg-error "missing term" "multiline strings" { target *-*-* } 18 } */ +/* { dg-bogus "warning" "warning in place of error" { target *-*-* } 11 } */ +/* { dg-bogus "warning" "warning in place of error" { target *-*-* } 14 } */ +/* { dg-bogus "warning" "warning in place of error" { target *-*-* } 15 } */ +/* { dg-bogus "warning" "warning in place of error" { target *-*-* } 18 } */ -- 2.7.4