This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
tweak for cpp error reporting
- To: gcc-patches at gcc dot gnu dot org
- Subject: tweak for cpp error reporting
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Sat, 29 Jan 2000 19:27:42 -0800
This makes error messages that come from -D or -A options on the
command line more user friendly. Example of previous odd behavior:
$ ./cpp -Dfoo=bar -Dfoo=baz /dev/null
/dev/null:0: warning: `foo' redefined
warning: this is the location of the previous definition
This now comes out as
$ ./cpp -Dfoo=bar -Dfoo=baz /dev/null
<command line>: warning: `foo' redefined
It even gets this right:
$ echo '#define foo baz' | ./cpp -Dfoo=bar
<stdin>:1:15: warning: `foo' redefined
<command line>: warning: this is the location of the previous definition
zw
* cpperror.c (cpp_file_line_for_message): If 'line' is zero,
just print "<command line>". If 'filename' is null or an
empty string, print "<stdin>" for the filename.
* cpplib.c (do_define): Don't print the 'location of the
previous definition' message if we're still parsing the
command line.
(cpp_pedwarn_with_file_and_line): Always call
cpp_file_line_for_message.
===================================================================
Index: cpperror.c
--- cpperror.c 2000/01/19 23:47:13 1.20
+++ cpperror.c 2000/01/30 03:24:39
@@ -84,7 +84,11 @@ cpp_file_line_for_message (pfile, filena
const char *filename;
int line, column;
{
- if (column > 0)
+ if (filename == 0 || *filename == '\0')
+ filename = "<stdin>";
+ if (line == 0)
+ fputs (_("<command line>: "), stderr);
+ else if (column > 0)
fprintf (stderr, "%s:%d:%d: ", filename, line, column);
else
fprintf (stderr, "%s:%d: ", filename, line);
===================================================================
Index: cpplib.c
--- cpplib.c 2000/01/27 22:29:06 1.100
+++ cpplib.c 2000/01/30 03:24:40
@@ -685,7 +685,7 @@ do_define (pfile, keyword)
mdef.symlen, mdef.symnam);
else
cpp_pedwarn (pfile, "`%.*s' redefined", mdef.symlen, mdef.symnam);
- if (hp->type == T_MACRO)
+ if (hp->type == T_MACRO && CPP_OPTIONS (pfile)->done_initializing)
cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file,
hp->value.defn->line,
"this is the location of the previous definition");
@@ -3474,8 +3474,7 @@ cpp_pedwarn_with_file_and_line VPARAMS (
if (!CPP_OPTIONS (pfile)->pedantic_errors
&& CPP_OPTIONS (pfile)->inhibit_warnings)
return;
- if (file != NULL)
- cpp_file_line_for_message (pfile, file, line, -1);
+ cpp_file_line_for_message (pfile, file, line, -1);
v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msgid, ap);
va_end(ap);
}