[COMMITTED,06/14] ada: Fix spurious warning about redundant parentheses in range bound

Message ID 20250113105349.928779-6-poulhies@adacore.com
State Committed
Commit ef4448e0a0508db63581c27238d39e634268b5a2
Headers
Series [COMMITTED,01/14] ada: Fix parsing of raise expressions with no parens |

Commit Message

Marc Poulhiès Jan. 13, 2025, 10:53 a.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

Use the same logic for warning about redundant parentheses in lower and upper
bounds of a discrete range. This fixes a spurious warning that, if followed,
would render the code illegal.

gcc/ada/ChangeLog:

	* par-ch3.adb (P_Discrete_Range): Detect redundant parentheses in the
	lower bound like in the upper bound.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/par-ch3.adb | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
  

Patch

diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
index e58e2a2342b..fe727d7c094 100644
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -3061,7 +3061,16 @@  package body Ch3 is
          Range_Node := New_Node (N_Range, Token_Ptr);
          Set_Low_Bound (Range_Node, Expr_Node);
 
-         if Style_Check then
+         --  If the bound doesn't require parentheses, then emit a style
+         --  check. Parentheses that change an "expression" syntax node into a
+         --  "simple expression" are required; we filter those nodes both here
+         --  and inside Check_Xtra_Parens itself.
+
+         if Style_Check
+           and then Nkind (Expr_Node) not in N_Membership_Test
+                                           | N_Op_Boolean
+                                           | N_Short_Circuit
+         then
             Style.Check_Xtra_Parens (Expr_Node);
          end if;
 
@@ -3070,10 +3079,7 @@  package body Ch3 is
          Check_Simple_Expression (Expr_Node);
          Set_High_Bound (Range_Node, Expr_Node);
 
-         --  If the upper bound doesn't require parentheses, then emit a style
-         --  check. Parentheses that make "expression" syntax nodes a "simple
-         --  expression" are required; we filter those nodes both here and
-         --  inside Check_Xtra_Parens itself.
+         --  Check for extra parentheses like for the lower bound
 
          if Style_Check
            and then Nkind (Expr_Node) not in N_Membership_Test