Article View: gnu.gcc.bug
Article #318GCC 2.2.2 does not warn about `1<=i<=N'
From: Paul Eggert
Date: Fri, 07 Aug 1992 22:44
Date: Fri, 07 Aug 1992 22:44
45 lines
2075 bytes
2075 bytes
GCC 2.2.2 does not warn about C expressions like `1<=i<=N', which have
a different meaning than in traditional mathematics. Here is a patch.
Fri Aug 7 22:34:20 1992 Paul Eggert (eggert@twinsun.com)
* c-typeck.c (parser_build_binary_op): Warn about expressions like
`1<=i<=N'.
* invoke.texi: Document warning.
===================================================================
RCS file: invoke.texi,v
retrieving revision 2.2.2.1
diff -c2 -r2.2.2.1 invoke.texi
*** invoke.texi 1992/08/01 03:27:09 2.2.2.1
--- invoke.texi 1992/08/07 22:22:36
***************
*** 616,619 ****
--- 616,624 ----
@item
+ A comparison like @samp{x<=y<=z} appears; this is equivalent to
+ @samp{(x<=y ? 1 : 0) <= z}, which is a different interpretation than
+ ordinary mathmatics.
+
+ @item
A storage-class specifier like @code{static} appears other than
at the beginning of a declaration. According to the C Standard,
===================================================================
RCS file: c-typeck.c,v
retrieving revision 2.2.2.3
diff -c2 -r2.2.2.3 c-typeck.c
*** c-typeck.c 1992/07/18 03:33:06 2.2.2.3
--- c-typeck.c 1992/08/07 22:34:20
***************
*** 2131,2134 ****
--- 2131,2139 ----
class = TREE_CODE_CLASS (TREE_CODE (result));
+ /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
+ if (class == '<' && extra_warnings
+ && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
+ warning ("comparisons like X<=Y<=Z do not have the usual meaning");
+
/* Record the code that was specified in the source,
for the sake of warnings about confusing nesting. */
Technical Details
Message-ID:
<9208072244.AA18568@farside.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggertShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert From: eggert@twinsun.COM (Paul Eggert) Subject: GCC 2.2.2 does not warn about `1<=i<=N' Message-ID: <9208072244.AA18568@farside.twinsun.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 7 Aug 1992 22:44:03 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 46