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]

No more multiline string constants


This patch removes the deprecated feature of multiline string
constants.

Since this eliminates a documented feature, I'm asking for an opinion
as to whether it should go in 3.1 or whether the patch should be held
for 3.2.  Note that the CPP manual for 3.0 said "this will be removed
in 3.1" in no uncertain terms.

I cannot bootstrap right now for what appear to be unrelated reasons,
and my connectivity is spotty for the next couple of weeks.  If the
patch is acceptable, and it turns out not to break anything, I would
appreciate it if someone would apply it for me.

-- 
zw        This is, no doubt, the rational strategy; quite possibly the
          only one that will work.  But it ignores the exigiencies of
          the tenure system and is therefore impractical.
          	-- Jerry Fodor, _The Mind Doesn't Work That Way_

	Remove multi-line string extension.

	* cpphash.h (struct cpp_reader): Remove mlstring_pos.
	* cpplex.c (unterminated): Delete.
	(parse_string): No string literal may extend over multiple
	lines.  Suppress the error when preprocessing assembly.

	* doc/cpp.texi: Update to match.
	* testsuite/gcc.dg/cpp/multiline.c: Update to match.

===================================================================
Index: cpphash.h
--- cpphash.h	2001/05/26 01:31:33	1.105
+++ cpphash.h	2001/07/05 20:14:09
@@ -283,10 +283,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).  */
-  cpp_lexer_pos mlstring_pos;
-
   /* Buffer to hold macro definition string.  */
   unsigned char *macro_buffer;
   unsigned int macro_buffer_len;
===================================================================
Index: cpplex.c
--- cpplex.c	2001/05/30 21:22:00	1.145
+++ cpplex.c	2001/07/05 20:14:09
@@ -92,7 +92,6 @@ static cpp_hashnode *parse_identifier PA
 static void parse_number PARAMS ((cpp_reader *, cpp_string *, cppchar_t, 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 int trigraph_ok PARAMS ((cpp_reader *, cppchar_t));
 static void save_comment PARAMS ((cpp_reader *, cpp_token *, const U_CHAR *));
 static void lex_percent PARAMS ((cpp_buffer *, cpp_token *));
@@ -596,24 +595,6 @@ parse_number (pfile, number, c, leading_
   POOL_COMMIT (pool, number->len + 1);
 }
 
-/* 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->mlstring_pos.line
-      && pfile->mlstring_pos.line != pfile->lexer_pos.line)
-    {
-      cpp_error_with_line (pfile, pfile->mlstring_pos.line,
-			   pfile->mlstring_pos.col,
-			   "possible start of unterminated string literal");
-      pfile->mlstring_pos.line = 0;
-    }
-}
-
 /* Subroutine of parse_string.  */
 static int
 unescaped_terminator_p (pfile, dest)
@@ -639,9 +620,7 @@ unescaped_terminator_p (pfile, dest)
 /* Parses a string, character constant, or angle-bracketed header file
    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.  */
+   this is the first NUL since embedded NULs are preserved.  */
 static void
 parse_string (pfile, token, terminator)
      cpp_reader *pfile;
@@ -664,51 +643,28 @@ parse_string (pfile, token, terminator)
       else
 	c = *buffer->cur++;
 
-    have_char:
       /* We need space for the terminating NUL.  */
       if (dest >= limit)
 	limit = _cpp_next_chunk (pool, 0, &dest);
 
-      if (c == EOF)
-	{
-	  unterminated (pfile, terminator);
-	  break;
-	}
-
       /* Handle trigraphs, escaped newlines etc.  */
       if (c == '?' || c == '\\')
 	c = skip_escaped_newlines (buffer, c);
 
       if (c == terminator && unescaped_terminator_p (pfile, dest))
 	{
-	  c = EOF;
+	  c = EOF;	/* consume the terminator */
 	  break;
 	}
-      else if (is_vspace (c))
+      else if (is_vspace (c) || c == EOF)
 	{
-	  /* 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 != '>')
-	    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);
-	      break;
-	    }
-
-	  cpp_pedwarn (pfile, "multi-line string literals are deprecated");
-	  if (pfile->mlstring_pos.line == 0)
-	    pfile->mlstring_pos = pfile->lexer_pos;
-	      
-	  c = handle_newline (buffer, c);
-	  *dest++ = '\n';
-	  goto have_char;
+	  /* 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.  */
+	  if (CPP_OPTION (pfile, lang) != CLK_ASM || terminator == '>')
+	    cpp_error (pfile, "missing terminating %c character", terminator);
+	  break;
 	}
       else if (c == '\0')
 	{
===================================================================
Index: doc/cpp.texi
--- doc/cpp.texi	2001/07/04 20:06:27	1.11
+++ doc/cpp.texi	2001/07/05 20:14:10
@@ -395,27 +395,9 @@ extremely confusing and should not be us
 readable.
 
 There is no way to prevent a backslash at the end of a line from being
-interpreted as a backslash-newline.
+interpreted as a backslash-newline.  This cannot affect any correct
+program, however.
 
-@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.
-
 @node Tokenization
 @section Tokenization
 
@@ -529,11 +511,10 @@ closing quote or angle bracket.  The pre
 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
 @dfn{Punctuators} are all the usual bits of punctuation which are
@@ -786,10 +767,10 @@ those are merely the typical uses.  Any 
 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
@@ -3686,14 +3667,11 @@ This is the same as @code{#pragma GCC po
 
 @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
 
===================================================================
Index: testsuite/gcc.dg/cpp/multiline.c
--- testsuite/gcc.dg/cpp/multiline.c	2001/03/03 18:10:34	1.2
+++ testsuite/gcc.dg/cpp/multiline.c	2001/07/05 20:14:10
@@ -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 } */


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