https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126379
Bug ID: 126379
Summary: 'Value Compilation Failure When Given a 2-Parameter
Function Argument
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: efmavourneen at axioaction dot org
CC: dkm at gcc dot gnu.org
Target Milestone: ---
GNAT incorrectly rejects a scalar 'Value attribute when its String argument is
supplied directly by a two-parameter function call, reporting “too many
arguments in call to Value_Enumeration_8”. Assigning the identical function
result to an intermediate `String` constant and passing that constant to 'Value
compiles successfully.
----------
--
-- Tick_Value_Compilation_Failure
--
-- Minimal reproducer for scalar 'Value when its String argument is supplied
directly by a function having two
-- parameters. GNAT 16.1.0 incorrectly reports too many arguments in the
generated call to Value_Enumeration_8.
--
procedure Tick_Value_Compilation_Failure is
type Selection is
(First,
Second);
function Next_Value (Text : String;
Position : in out Positive) return String;
function Next_Value (Text : String;
Position : in out Positive) return String is
begin
Position := Position + 1;
return Text;
end Next_Value;
Position : Positive := 1;
Value : constant Selection := Selection'Value (Next_Value ("First",
Position));
begin
if Value /= First then -- The compiler defect prevents execution from
reaching this consistency check.
raise Program_Error;
end if;
end Tick_Value_Compilation_Failure;
----------
--
-- Tick_Value_Workaround
--
-- Companion to Tick_Value_Compilation_Failure. Constraining the function
result in a String object before applying
-- scalar 'Value avoids the GNAT 16.1.0 expansion defect.
--
procedure Tick_Value_Workaround is
type Selection is
(First,
Second);
function Next_Value (Text : String;
Position : in out Positive) return String;
function Next_Value (Text : String;
Position : in out Positive) return String is
begin
Position := Position + 1;
return Text;
end Next_Value;
Position : Positive := 1;
Value_Image : constant String := Next_Value ("First", Position);
Value : constant Selection := Selection'Value (Value_Image);
begin
if Value /= First then -- Confirm that the workaround preserves the
intended value.
raise Program_Error;
end if;
end Tick_Value_Workaround;