[cfe-dev] clang-check wrongly adds forward definitions
Yves Rutschle via cfe-dev
cfe-dev at lists.llvm.org
Thu Jul 6 07:33:54 PDT 2017
Hello,
I'm using clang-check (combined with cproto) to fix old K&R
code that needs to compile with a compiler that doesn't like
that.
I have an issue with the way it adds an identifier forward
definition with it's not yet defined, e.g.:
#include <stddef.h>
struct foo {
int a;
struct s* b;
};
int main(void) {
struct foo f;
f.b = NULL;
return 0;
}
`struct s` was not defined, but this is not a problem for a pointer definition.
Then I run (v4.0.1):
$ clang-check -ast-print -fix-what-you-can in.c
typedef long ptrdiff_t;
typedef unsigned long size_t;
typedef int wchar_t;
typedef struct {
long long __clang_max_align_nonce1 __attribute__((aligned(_Alignof(long long))));
long double __clang_max_align_nonce2 __attribute__((aligned(_Alignof(long double))));
} max_align_t;
struct foo {
int a;
struct s;
struct s *b;
};
int main() {
struct foo f;
f.b = ((void *)0);
return 0;
}
The `struct s` right in the middle of the definition of `struct foo` confuse
all compilers. My understanding of the C standard is that this definition
should be either *before* the `struct foo` definition, or not exist at all
(which I think is the usual way to do it). Am I missing some reason it would
appear there?
I'll see if I manage to fix that by myself if no-one is interested :)
Cheers,
Y.
More information about the cfe-dev
mailing list