home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / c / 3287 < prev    next >
Encoding:
Text File  |  1992-12-30  |  11.9 KB  |  238 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
  3. From: diamond@jit533.jit.dec.com (Norman Diamond)
  4. Subject: Re: Standard conformance and GCC 2.3.3
  5. Message-ID: <C02I8I.58I@jrd.dec.com>
  6. Sender: usenet@jrd.dec.com (USENET News System)
  7. Nntp-Posting-Host: jit533.jit.dec.com
  8. Reply-To: diamond@jit.dec.com (Norman Diamond)
  9. Organization: Digital Equipment Corporation Japan , Tokyo
  10. References: <1992Dec30.011211.11409@netcom.com>
  11. Date: Wed, 30 Dec 1992 10:24:18 GMT
  12. Lines: 224
  13.  
  14. In article <1992Dec30.011211.11409@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes:
  15. >This report, and the examples given within it, may prove useful for some
  16. >readers of comp.std.c who are attempting to assess the level of standard
  17. >conformace provided by GCC
  18.  
  19. or who use GCC to try to verify whether a program is strictly conforming :-)
  20.  
  21. >Most (but not all) of these twenty bugs are problems with standard conformance.
  22.  
  23. I think you should have stated which ones you believe to be conformance issues.
  24. >-----------------------------------------------------------------------------
  25. >#1)  GCC [-pedantic-errors] fails to detect the error in the following code
  26. >void foo () {
  27. >  extern void bar (int i, ...);
  28. >  bar (99, 88, 77);
  29. >}
  30. >void bar (int i, int j, int k) { }      /* ERROR */
  31.  
  32. The call is irrelevant.  The two definitions are incompatible and the result
  33. is undefined (ANSI Classic 3.1.2.6).  However, I do not see a violation of any
  34. constraint here, so GCC's silence does not indicate a failure to conform.  A
  35. diagnostic would be nice for quality, perhaps -hyper-pedantic-errors :-)
  36. >-----------------------------------------------------------------------------
  37. >#2)  GCC [-pedantic-errors] fails to detect the error in the following code
  38. >unsigned long overflow = LONG_MAX + 3; /* ERROR */
  39.  
  40. Again I see no violation of a constrant.
  41. >-----------------------------------------------------------------------------
  42. >#3)  GCC incorrectly flags an error on the following standard-conformant code
  43. >     when the -pedantic-errors option is in effect.
  44. >typedef int T;
  45. >void test_1 (int T) { }
  46.  
  47. Spurious diagnostics are allowed.  Does GCC proceed to produce a valid result,
  48. i.e. can the program be executed with correct output?
  49.  
  50. Incidentally, it seems rather easy to misread ANSI Classic 3.7.1, page 83
  51. line 9, without realizing that the "If" antecedent in line 7 should apply
  52. to this sentence as well.
  53. >-----------------------------------------------------------------------------
  54. >#4)  On x86 machines, GCC fails to properly implement explicit floating-point
  55. >     casts of those floating-point expressions which get evaluated using the
  56. >     (internal) 80-bit floating-point format.
  57.  
  58. This might well be true, but your example didn't test for it.  You only cast
  59. a double operand to type double.
  60.  
  61. >     This causes the following program to yield a non-zero exit status.
  62. >double point_four = 0.4;
  63. >double point_one_six;
  64. >int main() {
  65. >  point_one_six = (point_four * point_four);
  66. >  if ((double)(point_four * point_four) != point_one_six) { return 1; }
  67. >  return 0;
  68. >}
  69.  
  70. This example tests (maybe) whether the expression (point_four * point_four)
  71. yields the same result, of type double, twice in a row.  The standard does
  72. not require this kind of consistency.  You might start by checking the value
  73. of FLT_ROUNDS.  Most possible values indicate implementation-defined rounding
  74. behavior, while -1 indicates indeterminable, and only a few values indicate
  75. moderately well defined behavior.
  76. >-----------------------------------------------------------------------------
  77. >#5)  GCC incorrectly issues an error for the following standard-conformant
  78. >     code.  (Note that `wchar_t' is the same as type `long int' on i486-svr4.)
  79. >typedef long int wchar_t;
  80. >wchar_t array5[4] = L"abcd";
  81.  
  82. This is a tough call.  ANSI Classic section 4.1.5 says that <stddef.h> defines
  83. the type wchar_t, and section 4.10 says that <stdlib.h> declares type wchar_t
  84. as described in 4.1.5.  But the standard does not guarantee that programmers
  85. can read the standard headers.  Both wordings "defined" and "declared" omit
  86. saying "implementation defined", so I'm not sure if you're guaranteed to know
  87. the implementation's choice for wchar_t.  It might be allowed to play dirty
  88. pool with you, as with enums.
  89.  
  90. However, even if they have to tell you what wchar_t is, spurious diagnostics
  91. are allowed.  What happens when you try executing the program?
  92. >-----------------------------------------------------------------------------
  93. >#6)  The following erroneous code causes GCC to crash with a signal 6.
  94. >extern volatile struct s evs;
  95. >void evs_test () { evs; }
  96.  
  97. The standard doesn't require diagnostics to be in a natural human language :-)
  98.  
  99. Uh, wait a minute.  Your expression "evs" neither evaluates nor modifies the
  100. object, so it is not necessary to know the size of the object.  Although an
  101. implementation-defined access occurs, the access includes neither evaluation
  102. nor modification.  I think your code is not erroneous, and must be accepted.
  103. (Now we finally agree that GCC failed to conform, but for different reasons.)
  104. >-----------------------------------------------------------------------------
  105. >#7)  When compiling an empty source file while the -pedantic-errors option
  106. >     is in effect, GCC will generate an error message for a line number which
  107. >     does not actually exist in the source file.
  108.  
  109. I believe that diagnostics are allowed to contain spurious line numbers unless
  110. they follow a #line directive.  (And of course a #line directive is allowed to
  111. command similar garbage.)
  112. >-----------------------------------------------------------------------------
  113. >#8)  GCC [-pedantic-errors] fails to issue errors for the following
  114. >void test_0 (char);
  115. >void test_0 (c) char c; { }
  116.  
  117. Again (as in #1) I see no violation of a constraint.
  118. >-----------------------------------------------------------------------------
  119. >#9)  GCC fails to issue errors in cases where a static function is referenced
  120. >     but never defined, even when the -pedantic-errors option is used.
  121. >static void s (); int main () { s (); return 1; }
  122.  
  123. Again I see no violation of a constraint.  Furthermore, if you returned
  124. EXIT_SUCCESS instead of 1, I believe it would be strictly conforming.
  125. Hard to believe, isn't it?  My best guess is that the invocation of s()
  126. acts as a no-op.  The standard doesn't seem to permit any other behavior.
  127. >-----------------------------------------------------------------------------
  128. >#10)  GCC [-pedantic-errors] fails to issue an error for the following invalid
  129. >void (*func_ptr) ();
  130. >int i;
  131. >void test () { func_ptr = i ? 0 : 0; }         /* ERROR */
  132.  
  133. The code looks valid to me.  The conditional expression  i ? 0 : 0  is an
  134. integral constant expression with value 0.  Null pointer constants can be
  135. assigned to function pointers.  (I expect no debate on this one.)
  136. >-----------------------------------------------------------------------------
  137. >#11)  GCC fails to issue errors for the following invalid C code involving
  138. >      comparison operators, even when the -pedantic-errors option is used.
  139. [Much editing by N.D.]
  140.  int b_array_src[3];
  141.  extern int u_array_src[];
  142. >int i;
  143. >void test_relational_operators () {
  144. >  i = & u_array_src > & b_array_src;            /* ERROR */
  145. >}
  146. >int u_array_src[20] = { 0 };    /* complete its type */
  147.  
  148. Hmm, we agree that GCC failed to conform this time, but I find the constraints
  149. for this very odd.  I wonder why there wasn't one allowance for "both operands
  150. are pointers to qualified or unqualified versions of compatible object or
  151. incomplete types."  The semantics could handle it without further adjustment.
  152. >-----------------------------------------------------------------------------
  153. >#12)  GCC fails to issue errors for the following invalid C code involving
  154. >      the binary `-' operator, even when the -pedantic-errors option is used.
  155. [Declarations similar to #11.]
  156. >  i = & u_array_src - & b_array_src;            /* ERROR */
  157.  
  158. A more serious problem.  Again, we agree that GCC failed to conform.
  159. >-----------------------------------------------------------------------------
  160. >#13)  GCC fails to issue errors for the following invalid C code involving
  161. >      invalid null pointer constants, even when the -pedantic-errors option
  162. >int (*fp) ();
  163. >void test () { fp = (void *) (void *) 0; }    /* ERROR */
  164.  
  165. To be a bit more precise, (void *) (void *) 0 is not a null pointer constant.
  166. (To be pedantic, if that means invalid null pointer constant, it also means
  167. invalid typedef, since it actually is neither.)  The code violates the
  168. constraints on the assignment operator, and we agree that GCC failed.
  169. >-----------------------------------------------------------------------------
  170. >#14)  GCC [-pedantic-errors] fails to issue errors for the following invalid
  171. [Declarations deleted but all had pointer types, i.e. all scalars -- N.D.]
  172. >  p_to_func_value = (p_to_func_type) p_to_object_value;         /* ERROR */
  173. >  p_to_func_value = (p_to_func_type) p_to_incomp1_value;        /* ERROR */
  174. >  p_to_func_value = (p_to_func_type) p_to_incomp2_value;        /* ERROR */
  175.  
  176. I see no violation of a constraint.
  177. [The behavior would be undefined, though on some machines you would even be
  178. able to do a function call using the result of any of those casts.]
  179. >-----------------------------------------------------------------------------
  180. >#15)  GCC [-pedantic-errors] fails to issue errors for the following invalid
  181. [Declarations deleted but all had pointer types, i.e. all scalars -- N.D.]
  182. >  p_to_object_value = (p_to_object_type) p_to_func_value;       /* ERROR */
  183. >  p_to_incomp1_value = (p_to_incomp1_type) p_to_func_value;     /* ERROR */
  184. >  p_to_incomp2_value = (p_to_incomp2_type) p_to_func_value;     /* ERROR */
  185.  
  186. Ditto.  [s/function call/arithmetic/.]
  187. >-----------------------------------------------------------------------------
  188. >#16)  GCC [-pedantic-errors] fails to issue errors for the following invalid
  189. >static int object_decl_6;
  190. >static int object_defn_6 = 0;
  191. >void test () {
  192. >    extern double object_decl_6;                /* ERROR */
  193. >    extern double object_defn_6;                /* ERROR */
  194. >}
  195.  
  196. As in #1, I see no violation of a constraint.  The behavior is undefined but
  197. silence is allowed.
  198. >-----------------------------------------------------------------------------
  199. >#17)  GCC [-pedantic-errors] fails to issue errors for the following invalid
  200. >void callee (char c);
  201. >void foobar () { void callee(); }     /* ERROR */
  202. >void callee (char c) { }
  203.  
  204. Ditto.
  205. >-----------------------------------------------------------------------------
  206. >#18)  GCC incorrectly issues an error for the following standard-conformant
  207. >      ANSI C code when the -pedantic-errors option is used.
  208. >extern const int func_1 ();
  209.  
  210. Spurious diagnostics are allowed.  In fact, a spurious warning on this one
  211. would be rather friendly, as long as the program still executes properly.
  212. What happened when you tried executing it?
  213. >-----------------------------------------------------------------------------
  214. >#19)  GCC fails to issue an error for the following pair of incompatible
  215. >      function declarations, even when the -pedantic-errors option is used.
  216. >extern const int func_4 ();
  217. >extern int func_4 ();                   /* ERROR */
  218.  
  219. For the fourth time, this does not violate a constraint.
  220. >-----------------------------------------------------------------------------
  221. >#20)  GCC incorrectly issues errors for the following standard-conformant
  222. >      ANSI C code when the -pedantic-errors option is used.
  223. >static enum E1 { red, green, blue};
  224. >static struct S1 { int member; };
  225. >static union U2 { int member; };
  226. >void foobar () {
  227. >    auto enum E2 { red, green, blue };
  228. >    auto struct S2 { int member; };
  229. >    auto union U2 { int member; };
  230. >}
  231.  
  232. Spurious diagnostics are allowed, though now they return to the status of
  233. unfriendly and misleading.  What happened when you tried executing it?
  234. --
  235. Norman Diamond                diamond@jit.dec.com
  236. If this were the company's opinion, I wouldn't be allowed to post it.
  237. Pardon me?  Or do I have to commit a crime first?
  238.