]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improve error for pre/post on generic formal subprogram in Ada 2012 mode
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 24 Jul 2025 08:20:40 +0000 (10:20 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 29 Sep 2025 09:43:40 +0000 (11:43 +0200)
Instead of saying that pragma placement is illegal, we now say that it
would be legal in Ada 2022.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pre_Post_Condition): Handle contracts on
generic formal subprograms like on declarations of access-to-subprogram
types.

gcc/ada/sem_prag.adb

index 1e115aae0195687d91c95482feac35a71a654130..28c5f1776dbb2699cde004983f991b8cbe6a4ab9 100644 (file)
@@ -5848,9 +5848,12 @@ package body Sem_Prag is
          --  For Ada 2022, pre/postconditions can appear on formal subprograms
 
          elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
-            and then Ada_Version >= Ada_2022
          then
-            null;
+            if Ada_Version < Ada_2022 then
+               Error_Msg_Ada_2022_Feature
+                 ("pre/postcondition on formal subprogram", Loc);
+               raise Pragma_Exit;
+            end if;
 
          --  An access-to-subprogram type can have pre/postconditions, which
          --  are both analyzed when attached to the type and copied to the