<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jul 6, 2017 at 7:33 AM, Yves Rutschle via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I'm using clang-check (combined with cproto) to fix old K&R<br>
code that needs to compile with a compiler that doesn't like<br>
that.<br>
<br>
I have an issue with the way it adds an identifier forward<br>
definition with it's not yet defined, e.g.:<br>
<br>
<br>
#include <stddef.h><br>
<br>
struct foo {<br>
    int a;<br>
    struct s* b;<br>
};<br>
<br>
int main(void) {<br>
    struct foo f;<br>
<br>
    f.b = NULL;<br>
<br>
    return 0;<br>
}<br>
<br>
<br>
<br>
`struct s` was not defined, but this is not a problem for a pointer definition.<br>
Then I run (v4.0.1):<br>
<br>
<br>
$ clang-check -ast-print -fix-what-you-can in.c<br>
typedef long ptrdiff_t;<br>
typedef unsigned long size_t;<br>
typedef int wchar_t;<br>
typedef struct {<br>
    long long __clang_max_align_nonce1 __attribute__((aligned(_<wbr>Alignof(long long))));<br>
    long double __clang_max_align_nonce2 __attribute__((aligned(_<wbr>Alignof(long double))));<br>
} max_align_t;<br>
struct foo {<br>
    int a;<br>
    struct s;<br>
    struct s *b;<br>
};<br>
int main() {<br>
    struct foo f;<br>
    f.b = ((void *)0);<br>
    return 0;<br>
}<br>
<br>
<br>
The `struct s` right in the middle of the definition of `struct foo` confuse<br>
all compilers. My understanding of the C standard is that this definition<br>
should be either *before* the `struct foo` definition, or not exist at all<br>
(which I think is the usual way to do it). Am I missing some reason it would<br>
appear there?<br></blockquote><div><br></div><div>Putting it there would be right for C++, which allows nested record types.  It's possible that the clang-check code doesn't take account of C's rather different rules in this area.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I'll see if I manage to fix that by myself if no-one is interested :)<br></blockquote><div><br></div><div>That'd be great.  I don't know whether it makes sense to have one piece of functionality that tries to handle both C and C++, or to separate them out.  That might depend on how much they have in common.</div><div><br></div><div>-- James </div></div></div></div>