[cfe-dev] warning: declaration does not declare anything / error: no member named 'LOW' in 'STRUCT'

Frank Redeker via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 30 09:08:23 PDT 2018


Hello List,

Given the following piece of code.

typedef union {
	struct {
		unsigned char	LOW;
		unsigned char	HIGH;
	};
	unsigned short	SHORT;		
} UNION;

typedef struct {
	UNION; // <-- use of type only
	union {
		unsigned char	FOO;
	};
} STRUCT;

STRUCT	Variable;

void Function () {
	Variable.LOW = 1;
}


This code compiles without any error using gcc 7.2 (When compiling with
-ansi -pedantic I get the warning "ISO C90 doesn't support unnamed
structs/unions". If I add -std=c11 the warning disappears)

If I use clang 6.0 to compile (clang -c), I get the following output.

file.c:10:2: warning: declaration does not declare anything
[-Wmissing-declarations]
        UNION; // <-- use of type only
        ^~~~~
file.c:19:11: error: no member named 'LOW' in 'STRUCT'
        Variable.LOW = 1;
        ~~~~~~~~ ^
1 warning and 1 error generated.

The output is the same if add -std=c11/-std=gnu11 to the command line.

So my Question is. Is there a compiler switch to avoid this error? Or
would it help to use clang 7.0?


Thx
Frank


More information about the cfe-dev mailing list