cppchar_t));
static void create_literal PARAMS ((cpp_reader *, cpp_token *, const uchar *,
unsigned int, enum cpp_ttype));
+static bool warn_in_comment PARAMS ((cpp_reader *, _cpp_line_note *));
static int name_p PARAMS ((cpp_reader *, const cpp_string *));
static cppchar_t maybe_read_ucn PARAMS ((cpp_reader *, const uchar **));
static tokenrun *next_tokenrun PARAMS ((tokenrun *));
buffer->next_line = s + 1;
}
+/* Return true if the trigraph indicated by NOTE should be warned
+ about in a comment. */
+static bool
+warn_in_comment (pfile, note)
+ cpp_reader *pfile;
+ _cpp_line_note *note;
+{
+ const uchar *p;
+
+ /* Within comments we don't warn about trigraphs, unless the
+ trigraph forms an escaped newline, as that may change
+ behaviour. */
+ if (note->type != '/')
+ return false;
+
+ /* If -trigraphs, then this was an escaped newline iff the next note
+ is coincident. */
+ if (CPP_OPTION (pfile, trigraphs))
+ return note[1].pos == note->pos;
+
+ /* Otherwise, see if this forms an escaped newline. */
+ p = note->pos + 3;
+ while (is_nvspace (*p))
+ p++;
+
+ /* There might have been escaped newlines between the trigraph and the
+ newline we found. Hence the position test. */
+ return (*p == '\n' && p < note[1].pos);
+}
+
/* Process the notes created by add_line_note as far as the current
location. */
void
}
else if (_cpp_trigraph_map[note->type])
{
- if (!in_comment && CPP_OPTION (pfile, warn_trigraphs))
+ if (CPP_OPTION (pfile, warn_trigraphs)
+ && (!in_comment || warn_in_comment (pfile, note)))
{
if (CPP_OPTION (pfile, trigraphs))
cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
}
}
+ _cpp_process_line_notes (pfile, true);
return false;
}
return false;
buffer->cur++;
- if (CPP_PEDANTIC (pfile)
- && !pfile->state.skipping
- && !pfile->warned_dollar)
+ if (pfile->warn_dollars && !pfile->state.skipping)
{
- pfile->warned_dollar = true;
+ pfile->warn_dollars = false;
cpp_error (pfile, DL_PEDWARN, "'$' in identifier or number");
}
return result;
}
-/* An upper bound on the number of bytes needed to spell TOKEN,
- including preceding whitespace. */
+/* An upper bound on the number of bytes needed to spell TOKEN.
+ Does not include preceding whitespace. */
unsigned int
cpp_token_len (token)
const cpp_token *token;
switch (TOKEN_SPELL (token))
{
- default: len = 0; break;
+ default: len = 4; break;
case SPELL_LITERAL: len = token->val.str.len; break;
case SPELL_IDENT: len = NODE_LEN (token->val.node); break;
}
- /* 1 for whitespace, 4 for comment delimiters. */
- return len + 5;
+
+ return len;
}
/* Write the spelling of a token TOKEN to BUFFER. The buffer must
cpp_token_as_text (pfile, token)
cpp_reader *pfile;
const cpp_token *token;
-{
- unsigned int len = cpp_token_len (token);
+{
+ unsigned int len = cpp_token_len (token) + 1;
unsigned char *start = _cpp_unaligned_alloc (pfile, len), *end;
end = cpp_spell_token (pfile, token, start);