Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros "inside" enums are not expanded #377

Closed
fekir opened this issue Feb 18, 2021 · 2 comments
Closed

macros "inside" enums are not expanded #377

fekir opened this issue Feb 18, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@fekir
Copy link

fekir commented Feb 18, 2021

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;
  }
}

@andreasfertig andreasfertig added the bug Something isn't working label Feb 22, 2021
@andreasfertig
Copy link
Owner

Hello @fekir,

thanks for reporting this issue! Currently, C++ Insights did not match an EnumDecl at the translation unit level, simply because I didn't saw a reason. But macros, ... well ... , they change the game. A fix is on its way.

Andreas

andreasfertig added a commit that referenced this issue Feb 22, 2021
Fixed #377: Match EnumDecl at TU level.
@fekir
Copy link
Author

fekir commented Feb 24, 2021

Thank you @andreasfertig , I can confirm the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants