]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Compiler abort on call to expr. function for default discriminant
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 21 Aug 2018 14:44:46 +0000 (14:44 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 21 Aug 2018 14:44:46 +0000 (14:44 +0000)
If a discriminant specification has a default that is a call to an
expression function, that function has to be frozen at the point of a
call to the initialization procedure for an object of the record type,
even though the call does not appear to come from source.

2018-08-21  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

* sem_res.adb (Resolve_Call): Force the freezing of an
expression function that is called to provide a default value
for a defaulted discriminant in an object initialization.

gcc/testsuite/

* gnat.dg/expr_func5.adb: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263710 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/sem_res.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/expr_func5.adb [new file with mode: 0644]

index 31420a3d663f0ad852e463e6c5461500f0550f56..7bae0cfc813b021d2ffc05cc0693cc93c397e611 100644 (file)
@@ -1,3 +1,9 @@
+2018-08-21  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_res.adb (Resolve_Call): Force the freezing of an
+       expression function that is called to provide a default value
+       for a defaulted discriminant in an object initialization.
+
 2018-08-21  Hristian Kirtchev  <kirtchev@adacore.com>
 
        * libgnat/g-dynhta.adb, libgnat/g-dynhta.ads: New package
index ddfa5430a7b7a0effd9b055c1aa57c421b77b766..13612aa3bf53cf553e9eca512f0ad6afc73ac5ad 100644 (file)
@@ -6067,7 +6067,10 @@ package body Sem_Res is
       --  (including the body of another expression function) which would
       --  place the freeze node in the wrong scope. An expression function
       --  is frozen in the usual fashion, by the appearance of a real body,
-      --  or at the end of a declarative part.
+      --  or at the end of a declarative part. However an implcit call to
+      --  an expression function may appear when it is part of a default
+      --  expression in a call to an initialiation procedure, and must be
+      --  frozen now, even if the body is inserted at a later point.
 
       if Is_Entity_Name (Subp)
         and then not In_Spec_Expression
@@ -6076,6 +6079,14 @@ package body Sem_Res is
           (not Is_Expression_Function_Or_Completion (Entity (Subp))
             or else Scope (Entity (Subp)) = Current_Scope)
       then
+         if Is_Expression_Function (Entity (Subp)) then
+
+            --  Force freeze of expression function in call.
+
+            Set_Comes_From_Source (Subp, True);
+            Set_Must_Not_Freeze (Subp, False);
+         end if;
+
          Freeze_Expression (Subp);
       end if;
 
index 2c02ca1549aca199ffab17ce71d9c4c6e0e7b21d..a3d8dda36c298199253c001035422dcb5c2b6481 100644 (file)
@@ -1,3 +1,7 @@
+2018-08-21  Ed Schonberg  <schonberg@adacore.com>
+
+       * gnat.dg/expr_func5.adb: New testcase.
+
 2018-08-21  Hristian Kirtchev  <kirtchev@adacore.com>
 
        * gnat.dg/dynhash.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/expr_func5.adb b/gcc/testsuite/gnat.dg/expr_func5.adb
new file mode 100644 (file)
index 0000000..34c4eb3
--- /dev/null
@@ -0,0 +1,10 @@
+--  { dg-do compile }
+
+procedure Expr_Func5 is
+   type T is (B);
+   function F return T is (B);
+   type R (W : T := F) is null record;
+   V : R;
+begin
+   null;
+end Expr_Func5;