diff mbox series

[Ada] Spurious error on Type'Access and <>

Message ID 20201217105008.GA112464@adacore.com
State New
Headers show
Series [Ada] Spurious error on Type'Access and <> | expand

Commit Message

Pierre-Marie de Rodat Dec. 17, 2020, 10:50 a.m. UTC
When mixing the <> in an aggregrate and the default initialization of
the Type involved by the box references Type'Access, GNAT may generate a
spurious error of the form:

   "Access" attribute cannot be applied to type

Fixed by only considering nodes that come from source in this legality
check: if the node is internally generated then it is assumed to be
legal.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_attr.adb (OK_Self_Reference): Return True if node does not
	come from source (e.g. a rewritten aggregate).
diff mbox series

Patch

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -782,6 +782,13 @@  package body Sem_Attr is
             Par : Node_Id;
 
          begin
+            --  If N does not come from source, the reference is assumed to be
+            --  valid.
+
+            if not Comes_From_Source (N) then
+               return True;
+            end if;
+
             Par := Parent (N);
             while Present (Par)
               and then
@@ -1032,9 +1039,7 @@  package body Sem_Attr is
                --  expression comes from source, e.g. when a single component
                --  association in an aggregate has a box association.
 
-               elsif Ada_Version >= Ada_2005
-                 and then OK_Self_Reference
-               then
+               elsif Ada_Version >= Ada_2005 and then OK_Self_Reference then
                   null;
 
                --  OK if reference to current instance of a protected object