<< Back to previous view

[PCC-396] enum forward declaration does not work Created: 31/Jul/12  Updated: 19/Apr/14

Status: Closed
Project: pcc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Nicolas Joly Assignee: Anders Magnusson
Resolution: Won't Fix Votes: 0
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

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

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

Comment by Anders Magnusson [ 31/Jul/12 09:43 PM ]
That is because doing so is explicitly forbidden in c99/c11:
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.
Comment by Nicolas Joly [ 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

Comment by Anders Magnusson [ 19/Apr/14 05:30 PM ]
No plans currently to support explicitly forbidden functionality.
Generated at Fri Oct 20 12:49:03 CEST 2017 using JIRA Enterprise Edition, Version: 3.13.1-#333.