[cfe-dev] retrieving anonymous struct decl name

John Leidel via cfe-dev cfe-dev at lists.llvm.org
Sun Dec 20 19:11:43 PST 2020

I'm still working on the same issue associated with translating
anonymous struct decl's to non-anonymous structs.  With the same
original example, I have the TagDecl for the nested struct definition.
Is there a way to retrieve the declaration name "first" from the

typedef struct test_case_t {
  struct {
     int value;
  } first[1];
  int second;
  int third[1];
} test_case_t;

As an example below, I grab the RecordDecl for the top-level struct,
then traverse each member using the decl_iterator.  I have other code
to examine each FieldDecl, but I'm specifically interested in the
following.  If I can dyn_cast to a TagDecl, then I'm looking at the
struct declaration.  I'm trying to retrieve the anonymous
DeclarationName and use it to reset the declaration of the nested
struct and its variable definition. Thoughts?

for(RecordDecl::decl_iterator iter = RD->decls_begin(), end =
RD->decls_end(); iter != end; ++iter) {
  if(TagDecl *TD = dyn_cast<TagDecl>(*iter)){
        // This sets the struct definition and instance name to test_case_t
        // how do I retrieve "first"?
        // this should induce struct first { }; struct first first[1];
        TD->setDeclName( ??? );

More information about the cfe-dev mailing list