[Ada] Change error message in Ada 2012 mode for misplaced "if" and "case"
Arnaud Charlet
charlet@adacore.com
Thu Aug 4 12:28:00 GMT 2011
GNAT was issuing a wrong message about a missing operand in some cases of
ill-parenthesized code in Ada 2012 mode. Now it issues a correct message about
the missing parentheses.
On the following code we get:
$ gcc -c -gnat2012 -gnaty3 pred.ads
pred.ads:5:30: conditional expression must be parenthesized
pred.ads:8:08: case expression must be parenthesized
---
package Pred is
type A is array (Integer range <>) of Integer
with Predicate => (for all J in A'Range =>
(for all K in A'Range =>
if J /= K then A (J) /= A (K)));
function F (X : Integer) return Integer
with Post =>
case X is when 0 => F'Result > 0,
when others => F'Result = 0;
end Pred;
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-08-04 Yannick Moy <moy@adacore.com>
* par-ch4.adb (P_Primary): preferentially issue an error message about
a missing parenthesis arount a conditional or case expression in Ada
2012 mode, if we detect that the alignment is not correct for a
statement.
-------------- next part --------------
Index: par-ch4.adb
===================================================================
--- par-ch4.adb (revision 177275)
+++ par-ch4.adb (working copy)
@@ -2445,9 +2445,16 @@
-- If this looks like a real if, defined as an IF appearing at
-- the start of a new line, then we consider we have a missing
- -- operand.
+ -- operand. If in Ada 2012 and the IF is not properly indented
+ -- for a statement, we prefer to issue a message about an ill-
+ -- parenthesized conditional expression.
- if Token_Is_At_Start_Of_Line then
+ if Token_Is_At_Start_Of_Line
+ and then not
+ (Ada_Version >= Ada_2012
+ and then Style_Check_Indentation /= 0
+ and then Start_Column rem Style_Check_Indentation /= 0)
+ then
Error_Msg_AP ("missing operand");
return Error;
@@ -2471,9 +2478,16 @@
-- If this looks like a real case, defined as a CASE appearing
-- the start of a new line, then we consider we have a missing
- -- operand.
+ -- operand. If in Ada 2012 and the CASE is not properly
+ -- indented for a statement, we prefer to issue a message about
+ -- an ill-parenthesized case expression.
- if Token_Is_At_Start_Of_Line then
+ if Token_Is_At_Start_Of_Line
+ and then not
+ (Ada_Version >= Ada_2012
+ and then Style_Check_Indentation /= 0
+ and then Start_Column rem Style_Check_Indentation /= 0)
+ then
Error_Msg_AP ("missing operand");
return Error;
More information about the Gcc-patches
mailing list