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

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

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

NetBSD 6.99.10 NetBSD 6.99.10 (LANFEUST) #1: Tue Jul 31 13:53:25 CEST 2012 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

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

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson made changes - 31/Jul/12 09:40 PM
Field Original Value New Value
Assignee Anders Magnusson [ ragge ]
Anders Magnusson added a comment - 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.

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

Anders Magnusson added a comment - 19/Apr/14 05:30 PM
No plans currently to support explicitly forbidden functionality.

Anders Magnusson made changes - 19/Apr/14 05:30 PM
Status Open [ 1 ] Closed [ 6 ]
Resolution Won't Fix [ 2 ]