* [Ada] Warn on not (not ..) if -gnatwr active
@ 2008-05-23 9:17 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2008-05-23 9:17 UTC (permalink / raw)
To: gcc-patches; +Cc: Robert Dewar
[-- Attachment #1: Type: text/plain, Size: 510 bytes --]
Tested on i686-linux, committed on trunk
The construct not (not ...) is now included as one of the redundant
constructs that generate a warning if -gnatwr is used:
1. procedure notnot (x, y : integer) is
2. begin
3. if not (not (x = y)) then
|
>>> warning: redundant double negation
4. return;
5. end if;
6. end;
See gnat.dg/notnot.adb
2008-05-20 Robert Dewar <dewar@adacore.com>
* sem_res.adb (Resolve_Op_Not): Warn on double negation
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 901 bytes --]
Index: sem_res.adb
===================================================================
--- sem_res.adb (revision 134945)
+++ sem_res.adb (working copy)
@@ -6975,6 +6975,19 @@ package body Sem_Res is
Error_Msg_N ("?not expression should be parenthesized here!", N);
end if;
+ -- Warn on double negation if checking redundant constructs
+
+ if Warn_On_Redundant_Constructs
+ and then Comes_From_Source (N)
+ and then Comes_From_Source (Right_Opnd (N))
+ and then Root_Type (Typ) = Standard_Boolean
+ and then Nkind (Right_Opnd (N)) = N_Op_Not
+ then
+ Error_Msg_N ("redundant double negation?", N);
+ end if;
+
+ -- Complete resolution and evaluation of NOT
+
Resolve (Right_Opnd (N), B_Typ);
Check_Unset_Reference (Right_Opnd (N));
Set_Etype (N, B_Typ);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-05-23 9:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-23 9:17 [Ada] Warn on not (not ..) if -gnatwr active Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).