diff options
author | Gary Dismukes <dismukes@adacore.com> | 2022-07-13 18:06:47 -0400 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2022-09-02 09:34:07 +0200 |
commit | 34d054d126f0fa870e36e37709199db84a5e1bd8 (patch) | |
tree | ea09fdf3b5bf33309cb4ecb57d2eb186ca76bb88 /gcc/ada | |
parent | 7f64e37c1f6d5c0e7db588171cfff194cd78d490 (diff) | |
download | gcc-34d054d126f0fa870e36e37709199db84a5e1bd8.zip gcc-34d054d126f0fa870e36e37709199db84a5e1bd8.tar.gz gcc-34d054d126f0fa870e36e37709199db84a5e1bd8.tar.bz2 |
[Ada] Error on return of object whose full view has undefaulted discriminants
The compiler wrongly reports an error about the expected type not
matching the same-named found type in a return statement for a function
whose result type has unknown discriminants when the full type is tagged
and has an undefaulted discriminant, and the return expression is an object
initialized by a function call. The processing for return statements that
creates an actual subtype based on the return expression type's underlying
type when that type has discriminants, and converts the expression to
the actual subtype, should only be done when the underlying discriminated
type is mutable (i.e., has defaulted discriminants). Otherwise the
unchecked conversion to the actual subtype (of the underlying full type)
can lead to a resolution problem later within Expand_Simple_Function_Return
in the expansion of tag assignments (because the target type of the
conversion is a full view and does not match the partial view of
the function's result type).
gcc/ada/
* exp_ch6.adb (Expand_Simple_Function_Return) Bypass creation of an actual
subtype and unchecked conversion to that subtype when the underlying type
of the expression has discriminants without defaults.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/exp_ch6.adb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index fad130d..fe3bb5b 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -6632,7 +6632,7 @@ package body Exp_Ch6 is begin if not Exp_Is_Function_Call - and then Has_Discriminants (Ubt) + and then Has_Defaulted_Discriminants (Ubt) and then not Is_Constrained (Ubt) and then not Has_Unchecked_Union (Ubt) then |