This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH to print column numbers in diagnostics
- From: Per Bothner <per at bothner dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 12 Feb 2005 13:26:38 -0800
- Subject: PATCH to print column numbers in diagnostics
This patch prints the column number if non-zero, but only
if USE_MAPPED_LOCATION. So for now it has limited usefulness,
and it may be reasonable to defer until after the branch.
On the other hand, it seems pretty safe, and it may encourage
people to save column numbers in declarations and expressions.
An ilustration where this patch makes a difference, see this
patch: http://gcc.gnu.org/ml/gcc-patches/2005-02/msg00594.html
Here is a C++ example:
void foo ()
{
int x;
int y;
int x;
}
/tmp/err.cc: In function ‘void foo()’:
/tmp/err.cc:5:3: error: redeclaration of ‘int x’
/tmp/err.cc:3:3: error: ‘int x’ previously declared here
As an aside: Column 7 (the column of the declared identifier)
would be more useful than column 3 (the start column of the
declaration); consider: 'int x, y, x;'. Changing this would
presumably be a modest fix to the C++ parser.
Ok after 4.0 has branched? Ok now?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2005-02-12 Per Bothner <per@bothner.com>
* diagnostic.c (diagnostic_build_prefix): If USE_MAPPED_LOCATION
and we have a non-zero column-number, add it to the message.
Also factor out the diagnostic_kind_text.
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.c,v
retrieving revision 1.146
diff -u -p -r1.146 diagnostic.c
--- diagnostic.c 7 Feb 2005 15:53:26 -0000 1.146
+++ diagnostic.c 12 Feb 2005 20:59:43 -0000
@@ -133,15 +133,18 @@ diagnostic_build_prefix (diagnostic_info
#undef DEFINE_DIAGNOSTIC_KIND
"must-not-happen"
};
+ const char *text = _(diagnostic_kind_text[diagnostic->kind]);
expanded_location s = expand_location (diagnostic->location);
gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
- return s.file
- ? build_message_string ("%s:%d: %s",
- s.file, s.line,
- _(diagnostic_kind_text[diagnostic->kind]))
- : build_message_string ("%s: %s", progname,
- _(diagnostic_kind_text[diagnostic->kind]));
+ return
+ (s.file == NULL
+ ? build_message_string ("%s: %s", progname, text)
+#ifdef USE_MAPPED_LOCATION
+ : s.column != 0
+ ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
+#endif
+ : build_message_string ("%s:%d: %s", s.file, s.line, text));
}
/* Count a diagnostic. Return true if the message should be printed. */