From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3b4bed4f74b8ac49,start X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: GNAT messages and the not operator (pitfall alert!) Date: 1996/10/24 Message-ID: #1/1 X-Deja-AN: 191758115 organization: New York University newsgroups: comp.lang.ada Date: 1996-10-24T00:00:00+00:00 List-Id: Here is an entertaining little bit of error message stuff in GNAT. Someone submitted the following program, shown with its original message: 1. procedure t is 2. begin 3. if not 7 < 5 then | >>> no modular type available in this context 4. null; 5. end if; 6. end; Well, that error message is "correct", the expression "not 7" cannot be resolved. But it sure is confusing. The latest version of GNAT (3.08) gives: 1. procedure t is 2. begin 3. if not 7 < 5 then | >>> operand of not must be enclosed in parentheses 4. null; 5. end if; 6. 7. if (not 7) < 5 then | >>> no modular type available in this context 8. null; 9. end if; 10. 11. end; I have added the parenthesized case here to make sure we do the right thing! Now, a worse case, suppose that we *are* dealing with modular types, well then the extension of Ada 95 to allow not on such types has added a real pitfall to the language. Ada does not have many pitfalls. I mean by pitfall a case where you write something that looks reasonable, is legal and executes but does something completely different from what you expect (e.g. in C the case of if ("abc"=="abc") yielding false). Consider this program, which we now, as you see, generate a warning for: 1. with Text_IO; use Text_IO; 2. procedure t1 is 3. type m is mod 256; 4. a : m := 4; 5. b : m := 5; 6. begin 7. if not a < b then | >>> warning: operand of not operator should be parenthesized 8. Put_Line ("this is what I expect"); 9. else 10. Put_Line ("but this is what I get!"); 11. end if; 12. 13. if (not a) < b then 14. Put_Line ("this is not what I expect"); 15. else 16. Put_Line ("this is what I get, and I really asked for it!"); 17. end if; 18. end; I think this warning is quite reasonable, since I would *really* like people to use parens if they really want the situation shown on line 13!