examining this in detail showed that include file ordering means that
an enum is being referenced in a function prototype before its definition
(which according to C99 6.7.2.3 note 3 is not allowed), but the following code
snippet

void foo(enum bar);

enum bar { A, B, C };

void main(void)
{
foo(B);
}

when compiled results in

test.c: line 7: compiler error: strmemb

rather than a useful warning or error.

Description

While attempting to compile GDB 7.3.1 I discovered an error
/var/cvs/NetBSD-current/src/external/gpl3/gdb/dist/gdb/i386-tdep.c, line 7187: warning: implicit conversion of argument 2 due to prototype
/var/cvs/NetBSD-current/src/external/gpl3/gdb/dist/gdb/i386-tdep.c, line 7187: compiler error: strmemb
examining this in detail showed that include file ordering means that
an enum is being referenced in a function prototype before its definition
(which according to C99 6.7.2.3 note 3 is not allowed), but the following code
snippet
void foo(enum bar);
enum bar { A, B, C };
void main(void)
{
foo(B);
}
when compiled results in
test.c: line 7: compiler error: strmemb
rather than a useful warning or error.

Hm, I'm wondering how this should be handled. gcc (4.2.1) also fails on this example, but nevertheless people tend to write such code.
Which gcc versions accept it? What I'm thinking about is if something more intelligent needs to be done here.

Anders Magnusson added a comment - 17/Mar/12 03:47 PM Hm, I'm wondering how this should be handled. gcc (4.2.1) also fails on this example, but nevertheless people tend to write such code.
Which gcc versions accept it? What I'm thinking about is if something more intelligent needs to be done here.

Iain Hibbert added a comment - 18/Mar/12 09:23 AM sorry, the gcc version was 4.5.3 but it seems I reduced the code too much and it was also giving a warning
the actual code is too big to fit in the margin here, but a better example is
typedef enum bar foo_t (void);
void foo (foo_t);
enum bar { A, B, C };
enum bar func (void);
void main (void)
{
foo (func);
}
which gcc accepts but pcc still fails, with
enum.c, line 11: warning: implicit conversion of argument 1 due to prototype
enum.c, line 11: compiler error: strmemb
(I think as mentioned previously, the code is wrong to do that, it is an include file out of order problem)

Just adding "enum bar;" first in the first example shows the problem.
I think that pcc should delay the prototype content check until the function is referenced, but that requires some internal rewriting.

Anders Magnusson added a comment - 18/Mar/12 01:27 PM Just adding "enum bar;" first in the first example shows the problem.
I think that pcc should delay the prototype content check until the function is referenced, but that requires some internal rewriting.