This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ada/41286] New: a warning about renamed function result is possibly confusing
- From: "bauhaus at futureapps dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Sep 2009 20:06:57 -0000
- Subject: [Bug ada/41286] New: a warning about renamed function result is possibly confusing
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
GNAT issues warnings when a declaration renames
a function result object:
11. Text : String renames Get_Another;
|
>>> warning: renaming function result object is suspicious
>>> warning: function "Get_Another" will be called only once
>>> warning: suggest using an initialized constant object instead
If you look at the program below, where the declaration
of Text is inside a loop, the "once" part becomes
confusing, because Get_Line will be called during each
iteration of the loop surrounding the declaration.
(The history of this warning seems to be a
different confusion about identifier Text not renaming
the function Get_Line but its result.)
To reproduce:
$ gnatchop -r -w rnm.ada && gnatmake -gnatwa -gnatv rnm
I like to suggest then to change the wording of
the second warning line. Something like
warning: "Line" renames the result of this call only
or better that "pinpoints" the warning to the
line of the declaration of Text.
with Ada.Text_IO;
procedure Rnm is
function Get_Another return String is separate;
-- post: String'Length > 0
begin
loop
declare
Text : String renames Get_Another;
begin
Ada.Text_IO.Put(Text(1));
end;
end loop;
end Rnm;
with Ada.Text_IO;
separate(Rnm)
function Get_Another return String is
Result : String(1 .. 80);
Last : Natural;
begin
Ada.Text_IO.Get_Line(Result, Last);
if Last = 0 then
Result(1) := '?';
Last := 1;
end if;
return Result(1 .. Last);
end Get_Another;
--
Summary: a warning about renamed function result is possibly
confusing
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bauhaus at futureapps dot de
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41286