PCC enum bug

Chris Torek chris at mimsy.UUCP
Sat Oct 14 16:42:56 AEST 1989


In article <20046 at mimsy.UUCP> I posted a fix to pcc for

	enum this { that = 3 };
	main() {
		enum this { that = 3 };
		printf("I expect 3; I got %d\n", that);
		return (0);
	}

which produces

	I expect 3; I got 4

from many Unix C compilers.  Unfortunately, that fix accepted `benign'
redefinitions such as

	enum color { red, blue, peach };
	enum fruit { apple, pear, peach };

which are (according to the draft ANSI C standard) illegal.

Here is a different (shorter!) fix, which seems to work, and rejects
such redefinitions, while allowing local redefinitions (which persist
until a close brace).  I do not know why the psave() was there
before---it seems to have to do with debugger information and/or
disambiguation among nonunique structure member names---but taking it
out completely seems to do the trick.

[/usr/src/lib/mip/pftn.c]
RCS file: RCS/pftn.c,v
retrieving revision 1.3
retrieving revision 1.6
diff -c2 -r1.3 -r1.6
*** /tmp/,RCSt1000933	Sat Oct 14 02:39:42 1989
--- pftn.c	Sat Oct 14 02:39:42 1989
***************
*** 218,224 ****
  
  	case MOE:
- 		if( scl == class ){
- 			if( p->offset!= strucoff++ ) break;
- 			psave( idp );
- 			}
  		break;
--- 218,221 ----
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.bugs.4bsd.ucb-fixes mailing list