This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Raise_Expression in membership test causes test to fail


This patch implements Ada 2012 AI-0022, which specifies that a raise
expression that is executed in a predicate that is tested during the
execution of a membership test causes the test to fail (or succeed
for NOT IN), rather than raising an exception.

The following, compiled with -gnata:

     1. pragma Ada_2012;
     2. with Text_IO; use Text_IO;
     3. procedure RaiseEXMem is
     4.    function Is_Gnarly (X : Integer) return Boolean is
     5.    begin
     6.       return X > 20;
     7.    end Is_Gnarly;
     8.
     9.    subtype S is Integer with
    10.      Dynamic_Predicate => Is_Gnarly (S)
    11.      or else raise Program_Error;
    12.
    13. begin
    14.    if 10 in S then
    15.       Put_Line ("predicate was true (unexpected)!");
    16.    else
    17.       Put_Line ("predicate was false as expected!");
    18.    end if;
    19.
    20.    if 42 in S then
    21.       Put_Line ("predicate was true as expected!");
    22.    else
    23.       Put_Line ("predicate was false (unexpected)!");
    24.    end if;
    25.
    26.
    27. exception
    28.    when others =>
    29.       Put_Line ("unexpected exception was raised");
    30. end RaiseEXMem;

prints out

predicate was false as expected!
predicate was true as expected!

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

2013-04-11  Robert Dewar  <dewar@adacore.com>

	* atree.h: Add declarations for Flag255-Flag289 Fix declaration
	of Field30 (was wrong, but no effect, since not yet referenced by
	back end) Add declarations for Field31-Field35 Add declarations
	for Node31-Node35.
	* einfo.ads, einfo.adb (Has_Invariants): No longer applies to
	procedures.
	(Has_Predicates): No longer applies to functions.
	(Is_Predicate_Function): New flag.
	(Is_Predicate_Function_M): New flag.
	(Is_Invariant_Procedure): New flag.
	(Predicate_Function_M): New function.
	(Set_Predicate_Function_M): New procedure.
	* exp_ch11.adb (Expand_N_Raise_Expression): Take care of special
	case of appearing in predicate used for membership test.
	* exp_ch3.adb (Insert_Component_Invariant_Checks): Set
	Is_Invariant_Procedure flag.
	* exp_ch4.adb (Expand_Op_In): Call special predicate function
	that takes care of raise_expression nodes in the predicate.
	* exp_util.ads, exp_util.adb (Make_Predicate_Call): Add argument Mem for
	membership case.
	* sem_ch13.adb (Build_Predicate_Functions): New name for
	Build_Predicate_Function.  Major rewrite to take care of raise
	expression in predicate for membership tests.
	* sem_res.adb (Resolve_Actuals): Include both predicate functions
	in defense against infinite predicate function loops.
	* sinfo.ads, sinfo.adb (Convert_To_Return_False): New flag.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]