public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Spurious error on Type'Access and <>
@ 2020-12-17 10:50 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-12-17 10:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Arnaud Charlet

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]

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).

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 993 bytes --]

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-17 10:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 10:50 [Ada] Spurious error on Type'Access and <> Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).