+2018-09-26 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch6.adb (Analyze_Function_Return): If the return type has
+ a dynamic_predicate, apply a Predicate_Check to the expression,
+ given that it is implicitly converted to the return type.
+ Exclude case expressions from the check, because in this context
+ the expression is expanded into individual return statements.
+
2018-09-26 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Task_Type>: In
Apply_Constraint_Check (Expr, R_Type);
+ -- The return value is converted to the return type of the function,
+ -- which implies a predicate check if the return type is predicated.
+ -- We do not apply the check to a case expression because it will
+ -- be expanded into a series of return statements, each of which
+ -- will receive a predicate check.
+
+ if Nkind (Expr) /= N_Case_Expression then
+ Apply_Predicate_Check (Expr, R_Type);
+ end if;
+
-- Ada 2005 (AI-318-02): When the result type is an anonymous access
-- type, apply an implicit conversion of the expression to that type
-- to force appropriate static and run-time accessibility checks.
+2018-09-26 Ed Schonberg <schonberg@adacore.com>
+
+ * gnat.dg/predicate3.adb, gnat.dg/predicate3_pkg.ads: New
+ testcase.
+
2018-09-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/67656
--- /dev/null
+-- { dg-do run }
+-- { dg-options "-gnata" }
+
+with Ada.Assertions, Ada.Text_IO;
+use Ada.Assertions, Ada.Text_IO;
+
+with Predicate3_Pkg;
+use Predicate3_Pkg;
+
+procedure Predicate3 is
+ Got_Assertion : Boolean := False;
+begin
+
+ begin
+ Put_Line (Good (C)'Image);
+ exception
+ when Assertion_Error =>
+ Got_Assertion := True;
+ end;
+
+ if not Got_Assertion then
+ raise Program_Error;
+ end if;
+
+ Got_Assertion := False;
+ declare
+ X: Priv;
+ begin
+ X := Wrong;
+ exception
+ when Assertion_Error =>
+ Got_Assertion := True;
+ end;
+
+ if not Got_Assertion then
+ raise Program_Error;
+ end if;
+
+end Predicate3;
--- /dev/null
+package Predicate3_Pkg is
+
+ type Priv is private;
+ C: constant Priv;
+
+ function Test (X: Priv) return Boolean;
+ subtype Subt is Priv with Dynamic_Predicate => (Test (Subt));
+
+ function Wrong return Subt;
+ function Good (X: Subt) return Boolean;
+
+private
+
+ type Priv is new Integer;
+ C: constant Priv := -1;
+
+ function Test (X: Priv) return Boolean is (X > 0);
+
+ function Wrong return Subt is (-1);
+ function Good (X: Subt) return Boolean is (True);
+
+end Predicate3_Pkg;