diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2025-04-12 11:35:44 +0200 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2025-04-12 11:37:53 +0200 |
commit | ecef0d7c53d59a701bc09e2df8fbec5d4c61267a (patch) | |
tree | bd5b5d0e591862b69635f4c726ac4bdccd4d56db | |
parent | f417af3f9f94538c2600e78e6c60b61c29fdbf99 (diff) | |
download | gcc-ecef0d7c53d59a701bc09e2df8fbec5d4c61267a.zip gcc-ecef0d7c53d59a701bc09e2df8fbec5d4c61267a.tar.gz gcc-ecef0d7c53d59a701bc09e2df8fbec5d4c61267a.tar.bz2 |
Ada: Natural/Positive not ignored in subprogram renaming
The language says that the profile of a subprogram renaming-as-declaration
must be mode conformant with that of the renamed subprogram, and that the
parameter subtypes are taken from the renamed subprogram.
GNAT implements the rule, except when Natural and Positive are involved,
which may lead to the wrong conclusion that it does not.
gcc/ada/
PR ada/119643
* sem_ch8.adb (Inherit_Renamed_Profile): Add guard against the
peculiarities of Natural and Positive.
gcc/testsuite/
* gnat.dg/renaming17.adb: New test.
-rw-r--r-- | gcc/ada/sem_ch8.adb | 3 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/renaming17.adb | 17 |
2 files changed, 19 insertions, 1 deletions
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index d4ab44f..0a9ef41 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -9314,11 +9314,12 @@ package body Sem_Ch8 is -- If the new type is a renaming of the old one, as is the case -- for actuals in instances, retain its name, to simplify later - -- disambiguation. + -- disambiguation. Beware of Natural and Positive, see Cstand. if Nkind (Parent (New_T)) = N_Subtype_Declaration and then Is_Entity_Name (Subtype_Indication (Parent (New_T))) and then Entity (Subtype_Indication (Parent (New_T))) = Old_T + and then Scope (New_T) /= Standard_Standard then null; else diff --git a/gcc/testsuite/gnat.dg/renaming17.adb b/gcc/testsuite/gnat.dg/renaming17.adb new file mode 100644 index 0000000..d826433 --- /dev/null +++ b/gcc/testsuite/gnat.dg/renaming17.adb @@ -0,0 +1,17 @@ +-- { dg-do run } + +procedure Renaming17 is + + function Incr (V : Integer; I : Integer := 1) return Integer is + (V + I); + + function Incr_Ren (V : Integer; I : Positive := 1) return Positive + renames Incr; + + I : Integer; + +begin + I := Incr_Ren (-3); + I := Incr_Ren (-3, 2); + I := Incr_Ren (-3, 0); +end; |