This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
cpp0 misbehavior?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: cpp0 misbehavior?
- From: "Dennis I. Chernoivanov" <cdi at sparc dot spb dot su>
- Date: Wed, 16 Aug 2000 20:51:27 +0400
Hi,
I faced a problem with previous snapshot; sorry if this is already known
and/or fixed (or not a bug:). If a program has #pragma directives and has
an error after them, then wrong line numbers may be printed in error messages.
For example,
# cat err1
int
main ()
{
#pragma unknown
{
error;
}
}
# gcc -c err1.c
err1.c: In function `main':
err1.c:8: `error' undeclared (first use in this function)
err1.c:8: (Each undeclared identifier is reported only once
err1.c:8: for each function it appears in.)
Here is an error in line #8 reported (should be line #6). I found that
this is because cpp0 adds two redundant newlines after #pragma directive, as
follows:
# 1 "err1.c"
int
main ()
{
#pragma unknown
{
error;
}
}
I made a patch that works for me -- it's in attachment.
Hope this helps,
--cdi
P.S. All is fine with -traditional.
*** cpplex.c 2000/08/14 14:00:09 1.1
--- cpplex.c 2000/08/14 14:00:32
***************
*** 328,334 ****
/* End the previous line of text. */
if (pfile->need_newline)
! putc ('\n', print->outf);
pfile->need_newline = 0;
vfprintf (print->outf, fmt, ap);
--- 328,337 ----
/* End the previous line of text. */
if (pfile->need_newline)
! {
! putc ('\n', print->outf);
! print->lineno++;
! }
pfile->need_newline = 0;
vfprintf (print->outf, fmt, ap);
***************
*** 392,405 ****
if (token->flags & BOL)
{
if (token->type == CPP_HASH && pfile->token_list.directive)
{
process_directive (pfile, token);
continue;
}
-
- output_line_command (pfile, print, pfile->token_list.line);
- prev = 0;
}
if (token->type != CPP_PLACEMARKER)
--- 395,408 ----
if (token->flags & BOL)
{
+ output_line_command (pfile, print, pfile->token_list.line);
+ prev = 0;
+
if (token->type == CPP_HASH && pfile->token_list.directive)
{
process_directive (pfile, token);
continue;
}
}
if (token->type != CPP_PLACEMARKER)
*** cppmain.c 2000/08/14 14:00:16 1.1
--- cppmain.c 2000/08/14 14:02:12
***************
*** 216,221 ****
--- 216,222 ----
cpp_output_list (pfile, parse_out.outf, &pfile->token_list,
pfile->first_directive_token + 2);
putc ('\n', parse_out.outf);
+ parse_out.lineno++;
}
static void