diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-04-19 20:53:06 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-04-19 20:53:06 +0000 |
commit | 59dedcce1a97aa61d27ceeaeca94916599b4410b (patch) | |
tree | c18dfee98cd0004a33f644025c4dfb4c94a3a231 /gcc/cpphash.c | |
parent | b6ce796344f5c9e157ad581d412a106ab4c77cbd (diff) | |
download | gcc-59dedcce1a97aa61d27ceeaeca94916599b4410b.tar.gz |
* cpphash.c (special_symbol): Represent an empty macro with
"\r \r " not just "\r ".
(_cpp_macroexpand): Correct condition for the foo ( ) special
case.
(unsafe_chars): Handle EOF as second argument.
(push_macro_expansion): Simplify test for removing escape at
end. Do not trim both escapes if there is no text in between.
* gcc.dg/20000419-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@33267 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpphash.c')
-rw-r--r-- | gcc/cpphash.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/gcc/cpphash.c b/gcc/cpphash.c index 6f28295bca9..70d1147465d 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -908,7 +908,7 @@ special_symbol (hp, pfile) if (!buf) return; if (*buf == '\0') - buf = "\r "; + buf = "\r \r "; CPP_PUTS (pfile, buf, strlen (buf)); return; @@ -1075,14 +1075,14 @@ _cpp_macroexpand (pfile, hp) if (token != CPP_RPAREN) return; - /* If we got one arg but it was just whitespace, call that 0 args. */ - if (i == 1) + /* foo ( ) is equivalent to foo () unless foo takes exactly one + argument, in which case the former is allowed and the latter + is not. XXX C99 is silent on this rule, but it seems + inconsistent to me. */ + if (i == 1 && nargs != 1) { register U_CHAR *bp = ARG_BASE + args[0].raw; register U_CHAR *lim = bp + args[0].raw_length; - /* cpp.texi says for foo ( ) we provide one argument. - However, if foo wants just 0 arguments, treat this as 0. */ - if (nargs == 0) while (bp != lim && is_space(*bp)) bp++; if (bp == lim) @@ -1410,6 +1410,10 @@ unsafe_chars (pfile, c1, c2) cpp_reader *pfile; int c1, c2; { + /* If c2 is EOF, that's always safe. */ + if (c2 == EOF) + return 0; + switch (c1) { case EOF: @@ -1491,14 +1495,13 @@ push_macro_expansion (pfile, xbuf, len, hp) /* Likewise, avoid the extra space at the end of the macro expansion if this is safe. We can do a better job here since we can know what the next char will be. */ - if (len >= 3 - && xbuf[len-2] == '\r' - && xbuf[len-1] == ' ') - { - int c = CPP_BUF_PEEK (CPP_BUFFER (pfile)); - if (c == EOF || !unsafe_chars (pfile, xbuf[len-3], c)) - len -= 2; - } + if (len >= 3 && xbuf[len-2] == '\r' && xbuf[len-1] == ' ' + && !unsafe_chars (pfile, xbuf[len-3], CPP_BUF_PEEK (CPP_BUFFER (pfile)))) + len -= 2; + + /* If the total expansion is "\r \r", we must not trim both escapes. */ + if (len == 2 && advance_cur) + advance_cur = 0; mbuf = cpp_push_buffer (pfile, xbuf, len); if (mbuf == NULL) |