Skip to content

Handling of anonymous structs #4

@dmikushin

Description

@dmikushin

Hi @mlomb ,

In Linux the following error occurs in metacpp_cli:

Generated.cpp:10518:48: error: expected id-expression before ‘(’ token
10518 |                         type->SetSize(sizeof(::(unnamed union at /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h::6::)));

This is due to the fact that this field is anonymous:

/* Conversion state information.  */
typedef struct
{
  int __count;
  union
  {
    __WINT_TYPE__ __wch;
    char __wchb[4];
  } __value;		/* Value so far.  */
} __mbstate_t;

I've investigated ASTScrapper.cpp, and it turns out the handling of anonymous records is not implemented.

I don't know yet how to implement it, so the best what I can do is to disable them:

--- a/ASTScraper.cpp
+++ b/ASTScraper.cpp
@@ -198,6 +198,9 @@ namespace metacpp {
                                                return 0; // forward declaration
                                        }
                                }
+                               if (!cxxRecordDecl->getDeclName()) {
+                                       return 0; // TODO is anonymous
+                               }
                                templateArgs = ResolveCXXRecordTemplate(cxxRecordDecl, qualifiedName);
 
                                if (qualifiedName.GetName().size() == 0) {

With this change the MetaCPP example compiles successfully.

Could you advise me how the anonymous fields should be handled in a good way? I can only image some decltype taken from the explicit type spec. On the other hand, I think two identical types are not yet equal, so perhaps this idea won't work anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions