[gnu.gcc.bug] gcc-cpp bug

wood@dg-rtp.dg.com (Tom Wood) (11/10/89)

Here's an additional test and some patches to 1.35:

/*
 * Traditional preprocess test.  Works with and wihout -DT
 */

#ifndef T
  Do comments work on #endif?		yes /*
#endif
					 */
#endif

End first block. 

#ifndef T
  Are character constants processed?	'/*' yes
#endif

End second block

#ifndef T
  Are valid strings processed?		"yes /* "
#endif

End third block.

#ifndef T
  Are bad char constants taken?		'yep
  Are bad strings taken?		 " (ditto)
#endif

End fourth block.

#ifndef T
  Do bad char constants hide comments?	'yep /*
  Are bad strings hide comments?	 " (ditto) /*
#endif

End fifth block.
#include "/dev/null"

/*
 * Fixing the above may lead to spurrious output from this:
 */
#ifndef LIBDIR
#define LIBDIR          "/usr/local/lib/xtrek
#endif /* LIBDIR */

#ifndef FONTDIR
#define FONTDIR         LIBDIR"
#endif /* FONTDIR */

#define PFILE		LIBDIR/.planets"

Here's a set of patches to 1.35 cccp.c that fix these problems (and
one other involving numbers like 1.0e-DIGIT

*** gcc-1.35/cccp.c	Thu Nov  9 16:07:22 1989
--- gcc-1.35.00/cccp.c	Wed Aug 16 14:12:06 1989
***************
*** 1475,1485 ****
  	case '\n':
  	  ++ip->lineno;
  	  ++op->lineno;
! 	  if (traditional) {
! 	    /* Terminate the string at the newline and announce the newline. */
! 	    beg_of_line = ibp;
  	    goto while2end;
- 	  }
  	  if (pedantic || c == '\'') {
  	    error_with_line (line_for_error (start_line),
  			     "unterminated string or character constant");
--- 1393,1400 ----
  	case '\n':
  	  ++ip->lineno;
  	  ++op->lineno;
! 	  if (traditional)
  	    goto while2end;
  	  if (pedantic || c == '\'') {
  	    error_with_line (line_for_error (start_line),
  			     "unterminated string or character constant");
***************
*** 1637,1650 ****
  	    break;
  	  }
  	  *obp++ = c;
! 	  /* A sign can be part of a preprocessing number if it follows
! 	     an e.  However, ANSI and PCC treat this as the termination
! 	     of the pp-number.  The exponent token may be rescanned. */
  	  if (c == 'e' || c == 'E') {
! 	    if (ibp < limit && (*ibp == '+' || *ibp == '-')) {
  	      *obp++ = *ibp++;
- 	      break;
- 	    }
  	  }
  	}
  	break;
--- 1552,1562 ----
  	    break;
  	  }
  	  *obp++ = c;
! 	  /* A sign can be part of a preprocessing number
! 	     if it follows an e.  */
  	  if (c == 'e' || c == 'E') {
! 	    if (ibp < limit && (*ibp == '+' || *ibp == '-'))
  	      *obp++ = *ibp++;
  	  }
  	}
  	break;
***************
*** 1891,1908 ****
  		      }
  		    }
  		  }
- 		  else if (ip->macro)
- 		    break;
- 		  else if (*ibp == '\\' && ibp[1] == '\n') {
- 		    ibp += 2;
- 		    ++ip->lineno;
- 		  }
- 		  else if (*ibp == '/' && (ibp[1] == '*' ||
- 					   cplusplus && ibp[1] == '/')) {
- 		    ip->bufp = ibp;
- 		    skip_to_end_of_comment (ip, &ip->lineno);
- 		    ibp = ip->bufp;
- 		  }
  		  else break;
  		}
  		if (*ibp != '(')
--- 1803,1808 ----
***************
*** 2155,2161 ****
  	  if (unterminated) {
  	    if (traditional) {
  	      /* Traditional preprocessing permits unterminated strings.  */
! 	      /* --bp; This leaves the last character as output. */
  	      ip->bufp = bp;
  	      goto endloop1;
  	    }
--- 2055,2061 ----
  	  if (unterminated) {
  	    if (traditional) {
  	      /* Traditional preprocessing permits unterminated strings.  */
! 	      --bp;
  	      ip->bufp = bp;
  	      goto endloop1;
  	    }
***************
*** 3610,3617 ****
        break;
      case '\"':
      case '\'':
!       /* Skip even in traditional. */
!       bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno, 0, 0);
        break;
      case '\\':
        /* Char after backslash loses its special meaning.  */
--- 3504,3511 ----
        break;
      case '\"':
      case '\'':
!       if (!traditional)
! 	bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno, 0, 0);
        break;
      case '\\':
        /* Char after backslash loses its special meaning.  */
***************
*** 3970,3982 ****
        }
        bp++;
      } else if (c == '\n') {
-       if (traditional) {
- 	/* Unterminated strings and character constants are 'legal'.  */
- 	bp--;	/* Don't consume the newline. */
- 	if (eofp)
- 	  *eofp = 1;
- 	break;
-       }
        if (match == '\'') {
  	error_with_line (line_for_error (start_line),
  			 "unterminated character constant");
--- 3864,3869 ----
***************
*** 3985,3990 ****
--- 3872,3882 ----
  	  *eofp = 1;
  	break;
        }
+       if (traditional) {	/* Unterminated strings are 'legal'.  */
+ 	if (eofp)
+ 	  *eofp = 1;
+ 	break;
+       }
        if (count_newlines)
  	++*count_newlines;
      } else if (c == match)
***************
*** 4189,4202 ****
  	  for (; i < arglen; i++) {
  	    c = arg->raw[i];
  
! 	    /* Process newline escapes */
  	    if (c == '\n') {
! 	      c = arg->raw[++i];
! 	      if (c == '-' || is_space[c]) {
! 		if (c == '\n') i--;
! 		continue;
! 	      }
! 	      i--;	      
  	    }
  
  	    /* Internal sequences of whitespace are replaced by one space.  */
--- 4081,4091 ----
  	  for (; i < arglen; i++) {
  	    c = arg->raw[i];
  
! 	    /* Special markers Newline Space and Newline Newline
! 	       generate nothing for a stringified argument.  */
  	    if (c == '\n') {
! 	      i++;
! 	      continue;
  	    }
  
  	    /* Internal sequences of whitespace are replaced by one space.  */
---
			Tom Wood	(919) 248-6067
			Data General, Research Triangle Park, NC
			{the known world}!rti!xyzzy!wood