[COMMITTED,03/14] ada: Warn about redundant parentheses in upper range bounds

Message ID 20250113105349.928779-3-poulhies@adacore.com
State Committed
Commit 518fd9e9b18913997b9ed8120d2a85c7bd3528f9
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>

Fix a glitch in condition that effectively caused detection of redundant
parentheses in upper range bounds to be dead code.

gcc/ada/ChangeLog:

	* par-ch3.adb (P_Discrete_Range): Replace N_Subexpr, which was catching
	all subexpressions, with kinds that catch nodes that require
	parentheses to become "simple expressions".

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

---
 gcc/ada/par-ch3.adb | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
index edea6785512..e58e2a2342b 100644
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -3070,11 +3070,15 @@  package body Ch3 is
          Check_Simple_Expression (Expr_Node);
          Set_High_Bound (Range_Node, Expr_Node);
 
-         --  If Expr_Node (ignoring parentheses) is not a simple expression
-         --  then emit a style check.
+         --  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.
 
          if Style_Check
-           and then Nkind (Expr_Node) not in N_Op_Boolean | N_Subexpr
+           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;