[Ada] Spurious error on protected call in inherited postcondition

Message ID 20210507093821.GA140544@adacore.com
State New
Headers show
Series
  • [Ada] Spurious error on protected call in inherited postcondition
Related show

Commit Message

Pierre-Marie de Rodat May 7, 2021, 9:38 a.m.
An inherited class-wide precondition of a primitive of a protected type
cannot include a call to a protected primitive of the type, as specified
in AI12-0166.  This patch adds a guard to verify that this legality rule
applies only to a precondition and not to a postcondition.

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

gcc/ada/

	* exp_util.adb (Build_Class_Wide_Expression, Replace_Entity):
	Add guard to verify that the enclosing pragma is a precondition.

Patch

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -1327,6 +1327,7 @@  package body Exp_Util is
                  and then Is_Primitive_Wrapper (New_E)
                  and then Is_Primitive_Wrapper (Subp)
                  and then Scope (Subp) = Scope (New_E)
+                 and then Chars (Pragma_Identifier (Prag)) = Name_Precondition
                then
                   Error_Msg_Node_2 := Wrapped_Entity (Subp);
                   Error_Msg_NE