https://gcc.gnu.org/g:a8bfc4dede003c76123f44eaafb374cb6dbcc1ec

commit r15-4627-ga8bfc4dede003c76123f44eaafb374cb6dbcc1ec
Author: Raphaƫl AMIARD <ami...@adacore.com>
Date:   Wed Sep 4 08:24:26 2024 +0000

    ada: Inspect deferred constant completions in missing contexts
    
    Namely declare expressions and statement lists, which can have object
    declarations in -gnatX mode.
    
    gcc/ada/ChangeLog:
    
            * sem_util.ads: Introduce Inspect_Deferred_Constant_Completion
            on a single object declaration, to better factorize the code
            * sem_util.adb: Introduce aforementioned overload
            * sem_ch4.adb (Analyze_Expression_With_Actions): Check deferred
            constant completions
            * sem_ch5.adb (Analyze_Statements): Check deferred constant
            completions

Diff:
---
 gcc/ada/sem_ch4.adb  |  2 ++
 gcc/ada/sem_ch5.adb  |  2 ++
 gcc/ada/sem_util.adb | 16 ++++++++++------
 gcc/ada/sem_util.ads |  5 +++++
 4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 9afaa896e20b..2d9177772109 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -2414,6 +2414,8 @@ package body Sem_Ch4 is
 
          case Nkind (A) is
             when N_Object_Declaration =>
+               Inspect_Deferred_Constant_Completion (A);
+
                if Nkind (Object_Definition (A)) = N_Access_Definition then
                   Error_Msg_N
                     ("anonymous access type not allowed in declare_expression",
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 30fee6e65001..131195a78c7c 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4255,6 +4255,8 @@ package body Sem_Ch5 is
                  ("implicit label declaration for & is hidden#",
                   Identifier (S));
             end if;
+         else
+            Inspect_Deferred_Constant_Completion (S);
          end if;
 
          Next (S);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index ac64b1ca5496..12437cc5a4c8 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -14811,13 +14811,8 @@ package body Sem_Util is
    -- Inspect_Deferred_Constant_Completion --
    ------------------------------------------
 
-   procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
-      Decl : Node_Id;
-
+   procedure Inspect_Deferred_Constant_Completion (Decl : Node_Id) is
    begin
-      Decl := First (Decls);
-      while Present (Decl) loop
-
          --  Deferred constant signature
 
          if Nkind (Decl) = N_Object_Declaration
@@ -14838,6 +14833,15 @@ package body Sem_Util is
               Defining_Identifier (Decl));
          end if;
 
+   end Inspect_Deferred_Constant_Completion;
+
+   procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
+      Decl : Node_Id;
+
+   begin
+      Decl := First (Decls);
+      while Present (Decl) loop
+         Inspect_Deferred_Constant_Completion (Decl);
          Next (Decl);
       end loop;
    end Inspect_Deferred_Constant_Completion;
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index eccbd4351d01..22ee23aa4ab0 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -1718,6 +1718,11 @@ package Sem_Util is
    --  prefix is an access type, rewrite the access type node N (which is the
    --  prefix, e.g. of an indexed component) as an explicit dereference.
 
+   procedure Inspect_Deferred_Constant_Completion (Decl : Node_Id);
+   --  If Decl is a constant object declaration without a default value, check
+   --  whether it has been completed by a full constant declaration or an
+   --  Import pragma. Emit an error message if that is not the case.
+
    procedure Inspect_Deferred_Constant_Completion (Decls : List_Id);
    --  Examine all deferred constants in the declaration list Decls and check
    --  whether they have been completed by a full constant declaration or an

Reply via email to