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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!crdgw1!rdsunx.crd.ge.com!bart!volpe
  2. From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Standard conformance and GCC 2.3.3
  5. Message-ID: <1992Dec30.145741.12888@crd.ge.com>
  6. Date: 30 Dec 92 14:57:41 GMT
  7. References: <1992Dec30.011211.11409@netcom.com>
  8. Sender: volpe@bart (Christopher R Volpe)
  9. Reply-To: volpe@ausable.crd.ge.com
  10. Organization: GE Corporate Research & Development
  11. Lines: 138
  12. Nntp-Posting-Host: bart.crd.ge.com
  13.  
  14. In article <1992Dec30.011211.11409@netcom.com>, rfg@netcom.com (Ronald F. Guilmette) writes:
  15. |> Most (but not all) of these twenty bugs are problems with standard conformance.
  16. |> GCC is either issuing errors for valid ANSI C code or else it is failing to
  17. |> issue errors for constructs which violate some constraint given in the ANSI
  18. |> C standard.
  19.  
  20. It would be nice if the constraint in question were indicated. I would
  21. like some justification for calling these constraint violations.
  22.  
  23. |> 
  24. |> -----------------------------------------------------------------------------
  25. |> #1)  GCC fails to detect the error in the following code, even when the
  26. |>      -pedantic-errors option is used.
  27. |> 
  28. |> void foo ()
  29. |> {
  30. |>   extern void bar (int i, ...);
  31. |> 
  32. |>   bar (99, 88, 77);
  33. |> }
  34. |> 
  35. |> void bar (int i, int j, int k) { }      /* ERROR */
  36.  
  37. What's the constraint violation?  The declaration with the ellipsis is out
  38. of scope at the time the definition is seen, so the constraint in 3.5
  39. about compatible types does not apply. The result is undefined behavior, not
  40. a constraint violation.
  41.  
  42. |> -----------------------------------------------------------------------------
  43. |> #2)  GCC fails to detect the error in the following code, even when the
  44. |>      -pedantic-errors option is used.
  45. |> 
  46. |> unsigned long overflow = LONG_MAX + 3; /* ERROR */
  47.  
  48. Again, which constraint is violated? The section on initialization says
  49. nothing about overflow, so normal assignment rules apply. And in normal
  50. assignment, overflow results in undefined behavior.
  51.  
  52. |> -----------------------------------------------------------------------------
  53. |> #9)  GCC fails to issue errors in cases where a static function is referenced
  54. |>      but never defined, even when the -pedantic-errors option is used.
  55. |> 
  56. |>      Example:
  57. |> 
  58. |> static void s (); int main () { s (); return 1; }
  59.  
  60. Is this a new bug? I get the expected diagnostic from gcc 2.2.
  61.  
  62. |> -----------------------------------------------------------------------------
  63. |> #14)  GCC fails to issue errors for the following invalid C code involving
  64. |>       invalid pointer type conversions, even when the -pedantic-errors option
  65. |>       is used.
  66. |> 
  67. |> struct incomp1; /* never completed */
  68. |> struct incomp2; /* completed towards the end - may make a difference */
  69. |> 
  70. |> typedef int             *p_to_object_type;
  71. |> typedef struct incomp1  *p_to_incomp1_type;
  72. |> typedef struct incomp2  *p_to_incomp2_type;
  73. |> typedef int             (*p_to_func_type) ();
  74. |> 
  75. |> p_to_object_type        p_to_object_value;
  76. |> p_to_incomp1_type       p_to_incomp1_value;
  77. |> p_to_incomp2_type       p_to_incomp2_value;
  78. |> p_to_func_type          p_to_func_value;
  79. |> 
  80. |> void
  81. |> test ()
  82. |> {
  83. |>   p_to_func_value = (p_to_func_type) p_to_object_value;         /* ERROR */
  84. |>   p_to_func_value = (p_to_func_type) p_to_incomp1_value;        /* ERROR */
  85. |>   p_to_func_value = (p_to_func_type) p_to_incomp2_value;        /* ERROR */
  86. |> }
  87. |> 
  88. |> struct incomp2 { int i; };
  89.  
  90. What constraint is violated? The assignment proper stores a function 
  91. pointer value in a function pointer object in each case, so the types are
  92. compatible there. The only questionable thing is the cast. The cast is
  93. definitely illegal because it is not permitted in the "Semantics" section of
  94. 3.3.4, but the constraints section of 3.3.4 requires only that the operand have
  95. scalar type and that the cast specify scalar type. That constraint is not
  96. violated.
  97.  
  98. |> -----------------------------------------------------------------------------
  99. |> #15)  GCC fails to issue errors for the following invalid C code involving
  100. |>       invalid pointer type conversions, even when the -pedantic-errors option
  101. |>       is used.
  102. |> 
  103. |> struct incomp1; /* never completed */
  104. |> struct incomp2; /* completed towards the end - may make a difference */
  105. |> 
  106. |> typedef int             *p_to_object_type;
  107. |> typedef struct incomp1  *p_to_incomp1_type;
  108. |> typedef struct incomp2  *p_to_incomp2_type;
  109. |> typedef int             (*p_to_func_type) ();
  110. |> 
  111. |> p_to_object_type        p_to_object_value;
  112. |> p_to_incomp1_type       p_to_incomp1_value;
  113. |> p_to_incomp2_type       p_to_incomp2_value;
  114. |> p_to_func_type          p_to_func_value;
  115. |> 
  116. |> void
  117. |> test ()
  118. |> {
  119. |>   p_to_object_value = (p_to_object_type) p_to_func_value;       /* ERROR */
  120. |>   p_to_incomp1_value = (p_to_incomp1_type) p_to_func_value;     /* ERROR */
  121. |>   p_to_incomp2_value = (p_to_incomp2_type) p_to_func_value;     /* ERROR */
  122. |> }
  123. |> 
  124. |> struct incomp2 { int i; };
  125. |> -----------------------------------------------------------------------------
  126.  
  127. See my previous comments. Same thing applies here.
  128.  
  129. |> -----------------------------------------------------------------------------
  130. |> #20)  GCC incorrectly issues errors for the following standard-conformant
  131. |>       ANSI C code when the -pedantic-errors option is used.
  132. |> 
  133. |> static enum E1 { red, green, blue};
  134. |> static struct S1 { int member; };
  135. |> static union U2 { int member; };
  136. |> 
  137. |> void foobar ()
  138. |> {
  139. |>     auto enum E2 { red, green, blue };
  140. |>     auto struct S2 { int member; };
  141. |>     auto union U2 { int member; };
  142. |> }
  143.  
  144. In my version (2.2), I get warnings, not errors. The warnings it gives are
  145. perfectly reasonable.
  146.  
  147. -- 
  148. ==================
  149. Chris Volpe
  150. G.E. Corporate R&D
  151. volpecr@crd.ge.com
  152.