Skip to content

macros "inside" enums are not expanded #377

@fekir

Description

@fekir

I noticed this issue when playing with x-macros, this is a minimal example.

It does not depend on the complexity of the macro, and does not depend on #undef.

#undef X_MACRO
#define X_MACRO(iconid) iconid,
enum class icon_id {
    X_MACRO(action)
    X_MACRO(action2)
};

#undef X_MACRO
#define X_MACRO(iconid) case icon_id::iconid: return 0;
int to_int(icon_id id){
    switch(id){
        X_MACRO(action)
        X_MACRO(action2)
    }
}

I would expect it to expand to

#undef X_MACRO
#define X_MACRO(iconid) iconid,
enum class icon_id {
    action,
    action2,
};


#undef X_MACRO
#define X_MACRO(iconid) case icon_id::iconid: return 0;
int to_int(icon_id id) {
  switch(id) {
    case icon_id::action: return 0;
    case icon_id::action2: return 0;
  }
}

but it actually gets expanded to

#undef X_MACRO
#define X_MACRO(iconid) iconid,
enum class icon_id {
    X_MACRO(action)
    X_MACRO(action2)
};


#undef X_MACRO
#define X_MACRO(iconid) case icon_id::iconid: return 0;
int to_int(icon_id id) {
  switch(id) {
    case icon_id::action: return 0;
    case icon_id::action2: return 0;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions