]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Reject ambiguous function calls in interpolated string expressions
authorJavier Miranda <miranda@adacore.com>
Thu, 6 Jun 2024 12:06:53 +0000 (12:06 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 21 Jun 2024 08:34:22 +0000 (10:34 +0200)
When the interpolated expression is a call to an ambiguous call
the frontend does not reject it; erroneously accepts the call
and generates code that calls to one of them.

gcc/ada/

* sem_ch2.adb (Analyze_Interpolated_String_Literal): Reject
ambiguous function calls.

gcc/ada/sem_ch2.adb

index aae9990eb4d9bb7f8d5043301aa1fa3340337162..08cc75c9104c4bc9a9252a2cc493dd4ae9b4820a 100644 (file)
@@ -25,7 +25,9 @@
 
 with Atree;          use Atree;
 with Einfo;          use Einfo;
+with Einfo.Entities; use Einfo.Entities;
 with Einfo.Utils;    use Einfo.Utils;
+with Errout;         use Errout;
 with Ghost;          use Ghost;
 with Mutably_Tagged; use Mutably_Tagged;
 with Namet;          use Namet;
@@ -141,6 +143,14 @@ package body Sem_Ch2 is
       Str_Elem := First (Expressions (N));
       while Present (Str_Elem) loop
          Analyze (Str_Elem);
+
+         if Nkind (Str_Elem) = N_Identifier
+           and then Ekind (Entity (Str_Elem)) = E_Function
+           and then Is_Overloaded (Str_Elem)
+         then
+            Error_Msg_NE ("ambiguous call to&", Str_Elem, Entity (Str_Elem));
+         end if;
+
          Next (Str_Elem);
       end loop;
    end Analyze_Interpolated_String_Literal;