[COMMITTED,08/31] ada: Reject references to attribute Result in Exceptional_Cases

Message ID 20250107125350.619654-8-poulhies@adacore.com
State New
Headers
Series [COMMITTED,01/31] ada: Restrict previous change made to expansion of allocators |

Commit Message

Marc Poulhiès Jan. 7, 2025, 12:53 p.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

Functions with aspect Side_Effects should not reference attribute Result in
consequences of their aspect Exceptional_Cases.

gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Exceptional_Cases_In_Decl_Part): Reject
	references to attribute Result.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_prag.adb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index b7de1cd8afa..64b5b01869d 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -2216,7 +2216,8 @@  package body Sem_Prag is
       --  in the consequences of an exceptional contract unless they are either
       --  passed by reference or occur in the prefix of a reference to the 'Old
       --  attribute or as direct prefixes of attributes that do not actually
-      --  read data from the object (SPARK RM 6.1.9(1)).
+      --  read data from the object (SPARK RM 6.1.9(1)). References to
+      --  attribute Result should not occur either.
 
       -----------------
       -- Check_Param --
@@ -2266,6 +2267,10 @@  package body Sem_Prag is
                      then
                         return Skip;
                      end if;
+                  when Name_Result =>
+                     Error_Msg_N
+                       ("attribute Result in consequence of Exceptional_Cases",
+                        N);
                   when others => null;
                end case;