]> git.ipfire.org Git - thirdparty/gcc.git/commit
[Ada] Illegal limited function call accepted in a type conversion
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Aug 2019 09:49:46 +0000 (09:49 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Aug 2019 09:49:46 +0000 (09:49 +0000)
commitcb4340ba75af7f53d9c707492349430b0f1888c4
treeefa89048a24e83d59b1769b2e0507a1214159465
parent6b0b9e72e65174332399db15c438de5eb0de5aa0
[Ada] Illegal limited function call accepted in a type conversion

It's illegal to call a function with a result of an immutably limited
type inside a type conversion that's used in one of the special contexts
that allow such a function call by itself (see RM 7.5 (2.1-2.10)), such
as in the initialization expression of an object declaration. The
compiler was recursively applying OK_For_Limited_Init_In_05 to the
expression inside of a rewritten type conversion, rather than directly
to the Original_Node itself (which is what was cased on to get to the
type conversion case alternative), which allowed such illegal
initialization, and that's corrected by this fix. However, when the
expression is not a rewriting of a user-written conversion, the
recursive call to OK_For_Limited_Init_In_05 must be applied to the
Expression of the conversion.

2019-08-20  Gary Dismukes  <dismukes@adacore.com>

gcc/ada/

* sem_ch3.adb (OK_For_Limited_Init_In_05): In the case of type
conversions, apply the recursive call to the Original_Node of
the expression Exp rather than the Expression of the
Original_Node, in the case where Exp has been rewritten;
otherwise, when Original_Node is the same as Exp, apply the
recursive call to the Expression.
(Check_Initialization): Revise condition for special check on
type conversions of limited function calls to test Original_Node
(avoiding spurious errors on expanded unchecked conversions
applied to build-in-place dispatching calls).

gcc/testsuite/

* gnat.dg/type_conv2.adb, gnat.dg/type_conv2.ads: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274731 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ada/ChangeLog
gcc/ada/sem_ch3.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/type_conv2.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/type_conv2.ads [new file with mode: 0644]