Issue Details (XML | Word | Printable)

Key: PCC-396
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Nicolas Joly
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

enum forward declaration does not work

Created: 31/Jul/12 08:25 PM   Updated: 19/Apr/14 05:30 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Environment:
NetBSD lanfeust.sis.pasteur.fr 6.99.10 NetBSD 6.99.10 (LANFEUST) #1: Tue Jul 31 13:53:25 CEST 2012 njoly@lanfeust.sis.pasteur.fr:/local/src/NetBSD/obj.amd64/sys/arch/amd64/compile/LANFEUST amd64
pcc 1.1.0.DEVEL 20120731 for x86_64-unknown-netbsd6.99.10


 Description  « Hide
enum forward declaration, unlike struct, does not work with pcc. No problem with gcc.

njoly@lanfeust [tmp/pcc]> cat forward.c
enum e;
int f(enum e);

njoly@lanfeust [tmp/pcc]> pcc --version
pcc 1.1.0.DEVEL 20120731 for x86_64-unknown-netbsd6.99.10
njoly@lanfeust [tmp/pcc]> pcc -c forward.c; echo $?
forward.c, line 2: arg 1 enum undeclared
1

njoly@lanfeust [tmp/pcc]> gcc --version
gcc (NetBSD nb2 20110806) 4.5.3
njoly@lanfeust [tmp/pcc]> gcc -c forward.c; echo $?
0


 All   Comments   Change History      Sort Order: Descending order - Click to sort in ascending order
Anders Magnusson added a comment - 19/Apr/14 05:30 PM
No plans currently to support explicitly forbidden functionality.

Nicolas Joly added a comment - 01/Aug/12 12:48 AM
Oops, i missed it.

I found it while trying to compile -current NetBSD/amd64 where it failed for various source files that include <sys/kauth.> which includes the following:

struct vnode;
struct cwdinfo;
enum vtype;
[...]
kauth_action_t kauth_mode_to_action(mode_t);
kauth_action_t kauth_access_action(mode_t, enum vtype, mode_t);
kauth_action_t kauth_extattr_action(mode_t);

And produce the following message:
/local/src/NetBSD/src/sys/sys/kauth.h, line 486: arg 2 enum undeclared

This means that sys/kauth.h needs to include sys/vnode.h where the enum is defined
enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };


Anders Magnusson added a comment - 31/Jul/12 09:43 PM
That is because doing so is explicitly forbidden in c99/c11:

6.7.2.3
2 A type specifier of the form
         enum identifier
  without an enumerator list shall only appear after the type it specifies is complete.

The reason for this is that the size of an enum is unknown until the type declaration is complete.