Article View: gnu.gcc.bug
Article #199GCC 2.2.2 doesn't diagnose empty declarations in old-style functions
From: Paul Eggert
Date: Sat, 25 Jul 1992 00:47
Date: Sat, 25 Jul 1992 00:47
106 lines
3268 bytes
3268 bytes
GCC doesn't issue a diagnostic for the empty struct declaration in the
program
int main(c,v)
struct s {int a;};
int c;
char **v;
{ return 0; }
even though the program violates the following constraint, taken from ANSI
X3.159-1989, section 3.7.1, page 83, lines 7-8:
If the declarator includes an identifier list, each declaration in the
declaration list shall have at least one declarator ...
Here is a patch.
Sat Jul 25 00:41:12 1992 Paul Eggert (eggert@twinsun.com)
* c-parse.y (datadecl): Diagnose empty declarations in old-style
function headers.
* c-decl.c (shadow_tag_warned): New function.
===================================================================
RCS file: c-parse.y,v
retrieving revision 2.2
diff -c -r2.2 c-parse.y
*** c-parse.y 1992/05/21 18:08:40 2.2
--- c-parse.y 1992/07/25 00:04:28
***************
*** 581,587 ****
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2); }
| typed_declspecs ';'
! { shadow_tag ($1); }
| declmods ';'
{ pedwarn ("empty declaration"); }
;
--- 581,588 ----
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2); }
| typed_declspecs ';'
! { shadow_tag_warned ($1, 1);
! pedwarn ("empty declaration"); }
| declmods ';'
{ pedwarn ("empty declaration"); }
;
===================================================================
RCS file: c-decl.c,v
retrieving revision 2.2.2.1
diff -c -r2.2.2.1 c-decl.c
*** c-decl.c 1992/06/21 05:34:02 2.2.2.1
--- c-decl.c 1992/07/25 00:13:45
***************
*** 388,393 ****
--- 388,394 ----
static tree grokparms (), grokdeclarator ();
tree pushdecl ();
tree builtin_function ();
+ void shadow_tag_warned ();
static tree lookup_tag ();
static tree lookup_tag_reverse ();
***************
*** 2706,2713 ****
shadow_tag (declspecs)
tree declspecs;
{
int found_tag = 0;
- int warned = 0;
register tree link;
pending_invalid_xref = 0;
--- 2707,2721 ----
shadow_tag (declspecs)
tree declspecs;
{
+ shadow_tag_warned (declspecs, 0);
+ }
+
+ void
+ shadow_tag_warned (declspecs, warned)
+ tree declspecs;
+ int warned;
+ {
int found_tag = 0;
register tree link;
pending_invalid_xref = 0;
***************
*** 2728,2734 ****
if (name == 0)
{
! if (code != ENUMERAL_TYPE) /* Empty unnamed enum OK */
{
pedwarn ("unnamed struct/union that defines no instances");
warned = 1;
--- 2736,2742 ----
if (name == 0)
{
! if (!warned && code != ENUMERAL_TYPE) /* Empty unnamed enum OK */
{
pedwarn ("unnamed struct/union that defines no instances");
warned = 1;
Technical Details
Message-ID:
<9207250047.AA23321@farside.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggertShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert From: eggert@twinsun.COM (Paul Eggert) Newsgroups: gnu.gcc.bug Subject: GCC 2.2.2 doesn't diagnose empty declarations in old-style functions Message-ID: <9207250047.AA23321@farside.twinsun.com> Date: 25 Jul 92 00:47:18 GMT Sender: gnulists@ai.mit.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 106 Approved: bug-gcc@prep.ai.mit.edu