diff options
author | Steve Baird <baird@adacore.com> | 2024-05-23 17:11:42 -0700 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-06-21 10:34:18 +0200 |
commit | 244d02bb288a07f3252fc9ed38675b93a9a91225 (patch) | |
tree | b7a345f17e6c21d5237b27bae4fefa9c56bf0554 /gcc/ada/sem_ch4.adb | |
parent | c5aed359a563c48f616d58f708c398f8494d7731 (diff) | |
download | gcc-244d02bb288a07f3252fc9ed38675b93a9a91225.zip gcc-244d02bb288a07f3252fc9ed38675b93a9a91225.tar.gz gcc-244d02bb288a07f3252fc9ed38675b93a9a91225.tar.bz2 |
ada: Predefined arithmetic operators incorrectly treated as directly visible
In some cases, a predefined operator (e.g., the "+" operator for an
integer type) is incorrectly treated as being directly visible when
it is not. This can lead to both accepting operator uses that should
be rejected and also to incorrectly rejecting legal constructs as ambiguous
(for example, an expression "Foo + 1" where Foo is an overloaded function and
the "+" operator is directly visible for the result type of only one of
the possible callees).
gcc/ada/
* sem_ch4.adb (Is_Effectively_Visible_Operator): A new function.
(Check_Arithmetic_Pair): In paths where Add_One_Interp was
previously called unconditionally, instead call only if
Is_Effectively_Visible_Operator returns True.
(Check_Boolean_Pair): Likewise.
(Find_Unary_Types): Likewise.
Diffstat (limited to 'gcc/ada/sem_ch4.adb')
-rw-r--r-- | gcc/ada/sem_ch4.adb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 1175a34..dfeff02 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -270,6 +270,18 @@ package body Sem_Ch4 is -- these aspects can be achieved without larger modifications to the -- two-pass resolution algorithm. + function Is_Effectively_Visible_Operator + (N : Node_Id; Typ : Entity_Id) return Boolean + is (Is_Visible_Operator (N => N, Typ => Typ) + or else + -- test for a rewritten Foo."+" call + (N /= Original_Node (N) + and then Is_Effectively_Visible_Operator + (N => Original_Node (N), Typ => Typ)) + or else not Comes_From_Source (N)); + -- Return True iff either Is_Visible_Operator returns True or if + -- there is a reason it is ok for Is_Visible_Operator to return False. + function Possible_Type_For_Conditional_Expression (T1, T2 : Entity_Id) return Entity_Id; -- Given two types T1 and T2 that are _not_ compatible, return a type that @@ -6641,6 +6653,8 @@ package body Sem_Ch4 is and then (Covers (T1 => T1, T2 => T2) or else Covers (T1 => T2, T2 => T1)) + and then Is_Effectively_Visible_Operator + (N, Specific_Type (T1, T2)) then Add_One_Interp (N, Op_Id, Specific_Type (T1, T2)); end if; @@ -6670,6 +6684,8 @@ package body Sem_Ch4 is and then (Covers (T1 => T1, T2 => T2) or else Covers (T1 => T2, T2 => T1)) + and then Is_Effectively_Visible_Operator + (N, Specific_Type (T1, T2)) then Add_One_Interp (N, Op_Id, Specific_Type (T1, T2)); @@ -6713,6 +6729,8 @@ package body Sem_Ch4 is and then (Covers (T1 => T1, T2 => T2) or else Covers (T1 => T2, T2 => T1)) + and then Is_Effectively_Visible_Operator + (N, Specific_Type (T1, T2)) then Add_One_Interp (N, Op_Id, Specific_Type (T1, T2)); end if; @@ -7086,6 +7104,7 @@ package body Sem_Ch4 is T := Any_Modular; end if; + -- test Is_Effectively_Visible_Operator here ??? Add_One_Interp (N, Op_Id, T); end if; end Check_Boolean_Pair; @@ -7615,7 +7634,8 @@ package body Sem_Ch4 is then null; - else + elsif Is_Effectively_Visible_Operator (N, Base_Type (It.Typ)) + then Add_One_Interp (N, Op_Id, Base_Type (It.Typ)); end if; end if; |