You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was kicking the tires of 3C's rewriting of multi-decls containing structs a bit in preparation for working on #531, and I discovered that the current code doesn't handle forward declarations of structs properly. The following file:
structfwd*p;
rewrites to the following syntatically invalid code, with or without -alltypes:
struct }_Ptr<structfwd>p= ((void*)0);
My understanding of Clang's AST parsing behavior is that the first mention of struct fwd in any context in a translation unit is reported as a RecordDecl whether or not it has a body. If it has a body, it is the definition, otherwise it is a forward declaration; we can use RecordDecl::isCompleteDefinition to distinguish between these cases. Subsequent occurrences of struct fwd; by itself are reported as forward declarations, but subsequent mentions of struct fwd as part of other constructs are not reported as RecordDecls at all.
AFAIK, "forward declarations" of structs as part of other constructs have no significance in C, because the first mention of a struct, wherever it appears, will be treated as a forward declaration. (There is one edge case in which a standalone forward declaration does make a difference, but 3C won't modify those anyway.) So probably what we want to do is have all 3C code that handles struct definitions in multi-decls just ignore RecordDecls for which isCompleteDefinition returns false. I prototyped this change and it seemed to have the desired effect in the example above; I'll probably submit a PR later.
The text was updated successfully, but these errors were encountered:
I was kicking the tires of 3C's rewriting of multi-decls containing structs a bit in preparation for working on #531, and I discovered that the current code doesn't handle forward declarations of structs properly. The following file:
rewrites to the following syntatically invalid code, with or without
-alltypes
:My understanding of Clang's AST parsing behavior is that the first mention of
struct fwd
in any context in a translation unit is reported as aRecordDecl
whether or not it has a body. If it has a body, it is the definition, otherwise it is a forward declaration; we can useRecordDecl::isCompleteDefinition
to distinguish between these cases. Subsequent occurrences ofstruct fwd;
by itself are reported as forward declarations, but subsequent mentions ofstruct fwd
as part of other constructs are not reported asRecordDecl
s at all.AFAIK, "forward declarations" of structs as part of other constructs have no significance in C, because the first mention of a struct, wherever it appears, will be treated as a forward declaration. (There is one edge case in which a standalone forward declaration does make a difference, but 3C won't modify those anyway.) So probably what we want to do is have all 3C code that handles struct definitions in multi-decls just ignore
RecordDecl
s for whichisCompleteDefinition
returns false. I prototyped this change and it seemed to have the desired effect in the example above; I'll probably submit a PR later.The text was updated successfully, but these errors were encountered: