[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error messages with ranges

From: Manuel López-Ibáñez
Subject: Re: error messages with ranges
Date: Tue, 13 Oct 2009 13:09:47 +0200

>  Date: Sun, 11 Oct 2009 23:44:45 -0400
>  From: Richard Stallman <address@hidden>
>  To: address@hidden (Karl Berry)
>  Subject: Re: address@hidden: error messages with ranges]
>  I think this is not a good idea.
>  Putting multiple locations in one error message is not helpful
>  and makes it harder to read.
>  There are situations where GCC needs to mention two different
>  places in the source -- for instance, two conflicting declarations
>  for one symbol.  It does this by issuing two error messages, one
>  with each location.  The text states how they are related.

This is a different situation that is orthogonal to mentioning two
different places.

First, this option will be default to off. Second, this information
will be primarily parsed by programs not humans.

The goal here is to work towards supporting caret information in GCC
(as Clang and other compilers currently support and use as a major
selling point).

An example from Clang's webpage [1]:

 $ gcc-4.2 -fsyntax-only t.c
 t.c:7: error: invalid operands to binary + (have 'int' and 'struct A')
 $ clang -fsyntax-only t.c
 t.c:7:39: error: invalid operands to binary expression ('int' and 'struct A')
   return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X);
                         ~~~~~~~~~~~~~~ ^ ~~~~~

The caret '^' and the ranges shown by ~~~~~  are generated the
compiler (clang in this case). A fist step towards implementing this
is to have an option that prints range information in the location
line. This allows programs to parse gcc output and generate a wrapper
around gcc that provides caret diagnostics. This is already done by at
least one IDE to provide caret diagnostics using Clang. This also
allows developers to debug the range information in case the ranges
are not printed where they are expected.

In short, the goal is to implement in GCC, this option from Clang:

-f[no-]diagnostics-print-source-range-info: Print machine parsable
information about source ranges.
    This option, which defaults to off, controls whether or not Clang
prints information about source ranges in a machine parsable format
after the file/line/column number information. The information is a
simple sequence of brace enclosed ranges, where each range lists the
start and end line/column locations. For example, in this output:

    exprs.c:47:15:{47:8-47:14}{47:17-47:24}: error: invalid operands
to binary expression ('int *' and '_Complex float')
       P = (P-42) + Gamma*4;
           ~~~~~~ ^ ~~~~~~~

    The {}'s are generated by -fdiagnostics-print-source-range-info.

I can certainly update the patch to mention that this format should be
avoided for output that is meant to be read mainly by humans, and in
such case a single location or multiple errors are preferred.



[1] http://clang.llvm.org/diagnostics.html
[2] http://clang.llvm.org/docs/UsersManual.html#cl_diagnostics

reply via email to

[Prev in Thread] Current Thread [Next in Thread]