Bug 35886 - Bad location of error message
Summary: Bad location of error message
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.4.0
: P3 minor
Target Milestone: ---
Assignee: Samuel Tardieu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-09 13:17 UTC by Samuel Tardieu
Modified: 2009-10-03 12:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-04-09 13:27:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Tardieu 2008-04-09 13:17:47 UTC
GNAT switches the location of the full type and the incomplete type when a tagged type is completed with a non-tagged record:

% gcc -gnatv -c p.ads
GNAT 4.4.0 20080409 (experimental)
Copyright 1992-2008, Free Software Foundation, Inc.

Compiling: p.ads (source file time stamp: 2008-04-09 13:15:07)

     3.    type T is tagged;
                |
        >>> full declaration of type "T" defined at line 4 must be tagged

 6 lines: 1 error

-- 
package P is

   type T is tagged;
   type T is null record;

end P;
Comment 1 Arnaud Charlet 2008-05-12 22:34:34 UTC
Well, I must be blind, but I do not see a bad location here: GNAT complains
at line 3 that the full declaration "defined at line 4" must be tagged,
showing indeed the line where type T is declared as tagged.

Looks correct to me.

Arno
Comment 2 Samuel Tardieu 2008-05-12 22:43:19 UTC
I expect the error message to point at the full declaration itself, not the partial view, as the partial view had been analyzed correctly and had no error so far. When it says "full declaration of type T declared at XXX", I expect "XXX" to designate the partial view, not the other way around.

To take a similar situation, consider:

package T is
   X : constant Integer;
private
   X : constant Float := 3.0;
end T;

GNAT gives the error:

     4.    X : constant Float := 3.0;
           |
        >>> type does not match declaration at line 2

and not:

     2.    X : constant Integer;
           |
        >>> type doesn't match declaration at line 4

I think this is an anomaly, as this doesn't match the behaviour of GNAT in other similar cases (a completion of a declaration not fullfilling the initial promise).
Comment 3 Arnaud Charlet 2008-05-12 22:54:50 UTC
OK, classifying as an enhancement request, since there's no bug here, the error
message is correct.
Comment 4 Samuel Tardieu 2008-05-12 23:01:17 UTC
Given that this happens when currently analyzing "Id" (and not "Prev"), posting the error message on "Prev" instead of "Id" may be an historical typo (inversion between both parameters in the call to Error_Msg_NE).

For example, in the message

                   Error_Msg_NE (
                     "full declaration of } must be a record extension",
                     Prev, Id);

it seems more logical to print

  "full declaration of <type name> defined at ... must be a record extension"

and have the error point to the full view rather than the opposite. And if you look at the way the error message is expanded, you clearly see that "<type name> defined at ..." comes together as one sole entity, namely "}", so the grouping is "full declaration of (<type name> defined at ...) must be a record extension" rather than "(full declaration of <type name>) defined at ... must be a record extension". And the error location (where the error is posted) already gives a primary location which I expect to be the problematic one.

So I'm not sure this should be classified as an enhancement request only, as the grouping due to the expansion of "}" shows an anomaly. Anyway, a trivial patch has been proposed already, waiting for your approval.
Comment 5 Samuel Tardieu 2009-10-03 12:55:36 UTC
This has been fixed alreayd in SVN.