Bug 42014 - Inconsistent column number display for "In file incuded from"
Summary: Inconsistent column number display for "In file incuded from"
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.5.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, easyhack, patch
Depends on:
Blocks:
 
Reported: 2009-11-12 04:17 UTC by Chris
Modified: 2021-09-02 02:53 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-02-07 00:00:00


Attachments
Added LAST_SOURCE_COLUMN in while loop (502 bytes, patch)
2013-05-10 06:58 UTC, Shakthi Kannan
Details | Diff
adds column to output (291 bytes, patch)
2014-10-28 15:09 UTC, Justin Vreeland
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris 2009-11-12 04:17:06 UTC
In file included from a.h:3:0,
                 from c.cpp:2:

Notice there's a 0 on the first line, and no column number on the second line.
This affects any inflexible error parsing program.
In gcc/diagnostic.c line 245 there's a check for flag_show_column for the first error line but no check for the rest.
	{
	  map = INCLUDED_FROM (line_table, map);
	  if (flag_show_column)
	    pp_verbatim (context->printer,
			 "In file included from %s:%d:%d",
			 map->to_file,
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
	  else
	    pp_verbatim (context->printer,
			 "In file included from %s:%d",
			 map->to_file, LAST_SOURCE_LINE (map));
	  while (! MAIN_FILE_P (map))
	    {
	      map = INCLUDED_FROM (line_table, map);
	      pp_verbatim (context->printer,
			   ",\n                 from %s:%d",
			   map->to_file, LAST_SOURCE_LINE (map));
	    }
	  pp_verbatim (context->printer, ":");
	  pp_newline (context->printer);
	}
Comment 1 Andrew Pinski 2009-11-12 04:47:03 UTC
>This affects any inflexible error parsing program.

Considering flag_show_column controls the display of column info, it does not say always display it, only when aviable.
Comment 2 Chris 2009-11-12 05:14:37 UTC
(In reply to comment #1)
> >This affects any inflexible error parsing program.
> 
> Considering flag_show_column controls the display of column info, it does not
> say always display it, only when aviable.
> 
Should be consistent though.  Possibly remove the flag_show_column block or add another pp_verbatim LAST_SOURCE_COLUMN in the while loop.
Comment 3 Shakthi Kannan 2013-05-10 06:58:47 UTC
Created attachment 30079 [details]
Added LAST_SOURCE_COLUMN in while loop

Attached patch adds LAST_SOURCE_COLUMN to pp_verbatim function in the while loop present in diagnostic_report_current_module() to make the output consistent.
Comment 4 Justin Vreeland 2014-10-28 15:09:36 UTC
Created attachment 33832 [details]
adds column to output

The currently attached patch doesn't apply cleanly I'm uploading another that does, it's essentially the same patch.

Without patch:

In file included from /usr/include/c++/4.9.1/iostream:39:0,
                 from test.cxx:1:

With patch:

In file included from /extra/gcc/bug42014/patched/gcc/pkg/gcc/usr/include/c++/4.9.1/iostream:39:0,
                 from test.cxx:1,0:

Which matches the error location.
Comment 5 Marcin Baczyński 2016-06-03 15:26:33 UTC
Patch against the current trunk https://gcc.gnu.org/ml/gcc-patches/2016-06/msg00272.html
Comment 6 Martin Sebor 2017-02-07 17:09:36 UTC
Looks like a fix was proposed but the approval was made contingent on getting some a suite issue sorted out.  Marcin, did you manage to resolve the test suite issue with David's suggestion?

I'm moving the status to New.
Comment 7 Andrew Pinski 2021-09-02 02:53:39 UTC
Since r11-2092 we don't print the columns at all if the column was 0.
So mostly we get:

In file included from /usr/include/c++/4.9.1/iostream:39,
                 from test.cxx:1:


The code looks like:
              const char *line_col = maybe_line_and_column (s.line, col);
              static const char *const msgs[] =
                {
                 NULL,
                 N_("                 from"),
                 N_("In file included from"),   /* 2 */
                 N_("        included from"),
                 N_("In module"),               /* 4 */
                 N_("of module"),
                 N_("In module imported at"),   /* 6 */
                 N_("imported at"),
                };

              unsigned index = (was_module ? 6 : is_module ? 4
                                : need_inc ? 2 : 0) + !first;

              pp_verbatim (context->printer, "%s%s %r%s%s%R",
                           first ? "" : was_module ? ", " : ",\n",
                           _(msgs[index]),
                           "locus", s.file, line_col);



Where maybe_line_and_column does:
static const char *
maybe_line_and_column (int line, int col)
{
  static char result[32];

  if (line)
    {
      size_t l
        = snprintf (result, sizeof (result),
                    col >= 0 ? ":%d:%d" : ":%d", line, col);
      gcc_checking_assert (l < sizeof (result));
    }
  else
    result[0] = 0;
  return result;
}