This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

Here is a C++ example:
void foo ()
  int x;
  int y;
  int x;
/tmp/ In function ‘void foo()’:
/tmp/ error: redeclaration of ‘int x’
/tmp/ 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
2005-02-12  Per Bothner  <>

	* 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
+  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)
+     : s.column != 0
+     ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
+     : build_message_string ("%s:%d: %s", s.file, s.line, text));
 /* Count a diagnostic.  Return true if the message should be printed.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]