https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123902
Bug ID: 123902
Summary: Discriminants break untagged prefix notation
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: liam at liampwll dot com
CC: dkm at gcc dot gnu.org
Target Milestone: ---
The below program will produce the error 'example.adb:18:13: error: invisible
selector "F" for private type "T" defined at line 7':
pragma Extensions_Allowed (On);
with Ada.Assertions; use Ada.Assertions;
procedure Example is
package P is
type T (Discrim : Integer) is private;
function F (X : T) return Boolean
is (True);
private
type T (Discrim : Integer) is record
F : Boolean := False;
end record;
end P;
X : P.T (1);
begin
Assert (X.F);
end Example;
The error here occurs because the invisible selector check happens before the
object operation check for core extensions. Here's a fix assuming I haven't
missed anything:
modified gcc/ada/sem_ch4.adb
@@ -5758,9 +5758,9 @@ package body Sem_Ch4 is
-- Before declaring an error, check whether this is tagged
-- private type and a call to a primitive operation.
elsif Ada_Version >= Ada_2005
- and then Is_Tagged_Type (Prefix_Type)
+ and then (Is_Tagged_Type (Prefix_Type)
+ or else Core_Extensions_Allowed)
and then Try_Object_Operation (N)
then
return;
This also occurs for protected types as shown in the below program, but I'm not
sure if there might be any issues introduced by changing this or if untagged
prefix notation is even meant to apply to them.
pragma Extensions_Allowed (On);
with Ada.Assertions; use Ada.Assertions;
procedure Example is
package P is
protected type T is
private
function F return Boolean;
end T;
function F (X : T) return Boolean
is (True);
end P;
package body P is
protected body T is
function F return Boolean
is (False);
end T;
end P;
X : P.T;
begin
Assert (X.F);
end Example;