home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / c / 3294 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  11.7 KB

  1. Path: sparky!uunet!gatech!darwin.sura.net!zaphod.mps.ohio-state.edu!uwm.edu!rutgers!twwells!bill
  2. From: bill@twwells.com (T. William Wells)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Standard conformance and GCC 2.3.3
  5. Message-ID: <C038C4.D36@twwells.com>
  6. Date: 30 Dec 92 19:48:02 GMT
  7. References: <1992Dec30.011211.11409@netcom.com>
  8. Organization: None, Mt. Laurel, NJ
  9. Lines: 324
  10.  
  11. In article <1992Dec30.011211.11409@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes:
  12. : -----------------------------------------------------------------------------
  13. : #1)  GCC fails to detect the error in the following code, even when the
  14. :      -pedantic-errors option is used.
  15. :
  16. : void foo ()
  17. : {
  18. :   extern void bar (int i, ...);
  19. :
  20. :   bar (99, 88, 77);
  21. : }
  22. :
  23. : void bar (int i, int j, int k) { }      /* ERROR */
  24.  
  25. Yes. All declarations of the same object or function must have
  26. compatible types.
  27.  
  28. : -----------------------------------------------------------------------------
  29. : #2)  GCC fails to detect the error in the following code, even when the
  30. :      -pedantic-errors option is used.
  31. :
  32. : unsigned long overflow = LONG_MAX + 3; /* ERROR */
  33.  
  34. This is undefined and the compiler is not obligated to notice it.
  35.  
  36. : -----------------------------------------------------------------------------
  37. : #3)  GCC incorrectly flags an error on the following standard-conformant code
  38. :      when the -pedantic-errors option is in effect.
  39. :
  40. : typedef int T;
  41. : void test_1 (int T) { }
  42.  
  43. The relevant statement: "An identifier declared as a typedef name
  44. shall not be redeclared as a parameter". This is a correct
  45. diagnostic.
  46.  
  47. : -----------------------------------------------------------------------------
  48. : #4)  On x86 machines, GCC fails to properly implement explicit floating-point
  49. :      casts of those floating-point expressions which get evaluated using the
  50. :      (internal) 80-bit floating-point format.  This causes the following
  51. :      program to yield a non-zero exit status.
  52. :
  53. : double point_four = 0.4;
  54. : double point_one_six;
  55. :
  56. : int
  57. : main ()
  58. : {
  59. :   point_one_six = (point_four * point_four);
  60. :   if ((double)(point_four * point_four) != point_one_six)
  61. :     {
  62. :       return 1;
  63. :     }
  64. :   return 0;
  65. : }
  66.  
  67. The compiler is allowed to use whatever extended precision it
  68. wants for expressions. There is no requirement that this be
  69. consistent between expressions. The first expression could, for
  70. example, compute the results using pure double precision and the
  71. second could use 80 bits for intermediate results, resulting in
  72. the != being true. This is a quality of implementation issue.
  73.  
  74. : -----------------------------------------------------------------------------
  75. : #5)  GCC incorrectly issues an error for the following standard-conformant
  76. :      code.  (Note that `wchar_t' is the same as type `long int' on i486-svr4.)
  77. :
  78. : typedef long int wchar_t;
  79. : wchar_t array5[4] = L"abcd";
  80.  
  81. Yes, the compiler should allow that.
  82.  
  83. : -----------------------------------------------------------------------------
  84. : #6)  The following erroneous code causes GCC to crash with a signal 6.
  85. :
  86. : extern volatile struct s evs;
  87. : void evs_test () { evs; }
  88.  
  89. Am I missing something? This code looks valid. It declares an
  90. external struct that is volatile and then a function which
  91. references that structure. Of course, that just makes it worse!
  92.  
  93. : -----------------------------------------------------------------------------
  94. : #7)  When compiling an empty source file while the -pedantic-errors option
  95. :      is in effect, GCC will generate an error message for a line number which
  96. :      does not actually exist in the source file.  (The line number indicated
  97. :      in the error message is equal to the number of lines actually in the
  98. :      file plus one.)  Issuing error messages which reference non-existant
  99. :      source lines may cause some related tools (e.g. emacs) to go bonkers.
  100.  
  101. But this isn't standard violating.
  102.  
  103. : -----------------------------------------------------------------------------
  104. : #8)  GCC fails to issue errors for the following erroneous code, even when
  105. :      the -pedantic-errors option is in effect.  (Note that the argument type
  106. :      for the function is *not* a type which would result from integral
  107. :      promotions.)
  108. :
  109. : void test_0 (char);
  110. : void test_0 (c) char c; { }
  111.  
  112. Yes, there should be an error.
  113.  
  114. : -----------------------------------------------------------------------------
  115. : #9)  GCC fails to issue errors in cases where a static function is referenced
  116. :      but never defined, even when the -pedantic-errors option is used.
  117. :
  118. :      Example:
  119. :
  120. : static void s (); int main () { s (); return 1; }
  121.  
  122. Yes, there should be an error.
  123.  
  124. : -----------------------------------------------------------------------------
  125. : #10)  GCC fails to issue an error for the following invalid C code, even when
  126. :       the -pedantic-errors option is used.
  127. :
  128. : void (*func_ptr) ();
  129. : int i;
  130. : void test () { func_ptr = i ? 0 : 0; }         /* ERROR */
  131.  
  132. Yes, there should be an error.
  133.  
  134. : -----------------------------------------------------------------------------
  135. : #11)  GCC fails to issue errors for the following invalid C code involving
  136. :       comparison operators, even when the -pedantic-errors option is used.
  137. :
  138. : typedef int b_array[3];
  139. : typedef int u_array[];
  140. :
  141. : typedef b_array *b_array_ptr;
  142. : typedef u_array *u_array_ptr;
  143. :
  144. : b_array b_array_src;
  145. : extern u_array u_array_src;
  146. : int *ip;
  147. : int i;
  148. : b_array_ptr b_array_dest;
  149. : u_array_ptr u_array_dest;
  150. :
  151. : void test_relational_operators ()
  152. : {
  153. :   i = & u_array_src > & b_array_src;            /* ERROR */
  154. :   i = & b_array_src > & u_array_src;            /* ERROR */
  155. :
  156. :   i = & u_array_src <= & b_array_src;           /* ERROR */
  157. :   i = & b_array_src <= & u_array_src;           /* ERROR */
  158. :
  159. :   i = u_array_dest > b_array_dest;              /* ERROR */
  160. :   i = b_array_dest > u_array_dest;              /* ERROR */
  161. :
  162. :   i = u_array_dest <= b_array_dest;             /* ERROR */
  163. :   i = b_array_dest <= u_array_dest;             /* ERROR */
  164. : }
  165.  
  166. Yes, these all should fail because one of the operands is a
  167. pointer to a complete type and the other is a pointer to an
  168. incomplete type.
  169.  
  170. : -----------------------------------------------------------------------------
  171. : #12)  GCC fails to issue errors for the following invalid C code involving
  172. :       the binary `-' operator, even when the -pedantic-errors option is used.
  173. :
  174. : typedef int b_array[3];
  175. : typedef int u_array[];
  176. :
  177. : typedef b_array *b_array_ptr;
  178. : typedef u_array *u_array_ptr;
  179. :
  180. : b_array b_array_src;
  181. : extern u_array u_array_src;
  182. : int *ip;
  183. : int i;
  184. : b_array_ptr b_array_dest;
  185. : u_array_ptr u_array_dest;
  186. :
  187. : void test_pointer_subtraction ()
  188. : {
  189. :   i = & u_array_src - & b_array_src;            /* ERROR */
  190. :   i = & b_array_src - & u_array_src;            /* ERROR */
  191. :
  192. :   i = u_array_dest - b_array_dest;              /* ERROR */
  193. :   i = b_array_dest - u_array_dest;              /* ERROR */
  194. : }
  195.  
  196. These are not errors. Unlike comparison, subtract only requires
  197. compatibility between the unqualified pointed to types.
  198.  
  199. : -----------------------------------------------------------------------------
  200. : #13)  GCC fails to issue errors for the following invalid C code involving
  201. :       invalid null pointer constants, even when the -pedantic-errors option
  202. :       is used.  (GCC also fails to properly flag these kinds of invalid
  203. :       null pointer constants in other contexts as well.)
  204. :
  205. : int (*fp) ();
  206. : void test () { fp = (void *) (void *) 0; }    /* ERROR */
  207.  
  208. Right. This is an attempt to assign a null pointer of object type
  209. rather than a null pointer constant to the function pointer.
  210.  
  211. : -----------------------------------------------------------------------------
  212. : #14)  GCC fails to issue errors for the following invalid C code involving
  213. :       invalid pointer type conversions, even when the -pedantic-errors option
  214. :       is used.
  215. :
  216. : struct incomp1; /* never completed */
  217. : struct incomp2; /* completed towards the end - may make a difference */
  218. :
  219. : typedef int             *p_to_object_type;
  220. : typedef struct incomp1  *p_to_incomp1_type;
  221. : typedef struct incomp2  *p_to_incomp2_type;
  222. : typedef int             (*p_to_func_type) ();
  223. :
  224. : p_to_object_type        p_to_object_value;
  225. : p_to_incomp1_type       p_to_incomp1_value;
  226. : p_to_incomp2_type       p_to_incomp2_value;
  227. : p_to_func_type          p_to_func_value;
  228. :
  229. : void
  230. : test ()
  231. : {
  232. :   p_to_func_value = (p_to_func_type) p_to_object_value;         /* ERROR */
  233. :   p_to_func_value = (p_to_func_type) p_to_incomp1_value;        /* ERROR */
  234. :   p_to_func_value = (p_to_func_type) p_to_incomp2_value;        /* ERROR */
  235. : }
  236.  
  237. No, that's not an error. I thought so at first; however, a careful
  238. reading of the standard shows that these are undefined behavior,
  239. not illegal behavior.
  240.  
  241. : -----------------------------------------------------------------------------
  242. : #15)  GCC fails to issue errors for the following invalid C code involving
  243. :       invalid pointer type conversions, even when the -pedantic-errors option
  244. :       is used.
  245. :
  246. : struct incomp1; /* never completed */
  247. : struct incomp2; /* completed towards the end - may make a difference */
  248. :
  249. : typedef int             *p_to_object_type;
  250. : typedef struct incomp1  *p_to_incomp1_type;
  251. : typedef struct incomp2  *p_to_incomp2_type;
  252. : typedef int             (*p_to_func_type) ();
  253. :
  254. : p_to_object_type        p_to_object_value;
  255. : p_to_incomp1_type       p_to_incomp1_value;
  256. : p_to_incomp2_type       p_to_incomp2_value;
  257. : p_to_func_type          p_to_func_value;
  258. :
  259. : void
  260. : test ()
  261. : {
  262. :   p_to_object_value = (p_to_object_type) p_to_func_value;       /* ERROR */
  263. :   p_to_incomp1_value = (p_to_incomp1_type) p_to_func_value;     /* ERROR */
  264. :   p_to_incomp2_value = (p_to_incomp2_type) p_to_func_value;     /* ERROR */
  265. : }
  266.  
  267. As above, this is not an error.
  268.  
  269. : -----------------------------------------------------------------------------
  270. : #16)  GCC fails to issue errors for the following invalid C code involving
  271. :       local redeclarations of objects, even when the -pedantic-errors option
  272. :       is used.
  273. :
  274. : static int object_decl_6;
  275. : static int object_defn_6 = 0;
  276. :
  277. : void
  278. : test ()
  279. : {
  280. :     extern double object_decl_6;                /* ERROR */
  281. :     extern double object_defn_6;                /* ERROR */
  282. : }
  283.  
  284. This is undefined behavior; the compiler isn't required to issue
  285. a diagnostic.
  286.  
  287. : -----------------------------------------------------------------------------
  288. : #17)  GCC fails to issue errors for the following invalid C code involving
  289. :       incompatible redeclarations, even when the -pedantic-errors option
  290. :       is used.
  291. :
  292. : void callee (char c);
  293. : void foobar () { void callee(); }     /* ERROR */
  294. : void callee (char c) { }
  295.  
  296. Yes, that's an error.
  297.  
  298. : -----------------------------------------------------------------------------
  299. : #18)  GCC incorrectly issues an error for the following standard-conformant
  300. :       ANSI C code when the -pedantic-errors option is used.
  301. :
  302. : extern const int func_1 ();
  303.  
  304. Yes, that's acceptable code.
  305.  
  306. : -----------------------------------------------------------------------------
  307. : #19)  GCC fails to issue an error for the following pair of incompatible
  308. :       function declarations, even when the -pedantic-errors option is used.
  309. :
  310. : extern const int func_4 ();
  311. : extern int func_4 ();                   /* ERROR */
  312.  
  313. Yes, that's an error.
  314.  
  315. : -----------------------------------------------------------------------------
  316. : #20)  GCC incorrectly issues errors for the following standard-conformant
  317. :       ANSI C code when the -pedantic-errors option is used.
  318. :
  319. : static enum E1 { red, green, blue};
  320. : static struct S1 { int member; };
  321. : static union U2 { int member; };
  322. :
  323. : void foobar ()
  324. : {
  325. :       auto enum E2 { red, green, blue };
  326. :       auto struct S2 { int member; };
  327. :       auto union U2 { int member; };
  328. : }
  329.  
  330. Yes, those are all valid code.
  331.  
  332. ---
  333. Bill                            { rutgers | decwrl | telesci }!twwells!bill
  334. bill@twwells.com
  335.