Skip to content

Complex macros are not expanded #376

@SpriteOvO

Description

@SpriteOvO

Issue example: https://cppinsights.io/s/8931a54c

Input:

/* ... better-enums library code ... */

#include <cstdio>
#include <iostream>

BETTER_ENUM(Word, int, Hello, World)

int main()
{
#define ARR_SIZE 10
  
    const char arr[ARR_SIZE]{2,4,6,8};

    for(const char& c : arr)
    {
      printf("c=%c\n", c);
    }
  
    std::cout << (+Word::Hello)._to_string() << ", "
              << (+Word::World)._to_string() << "!"
              << std::endl;
}

Output:

/* ... better-enums library code ... */

#include <cstdio>
#include <iostream>

BETTER_ENUM(Word, int, Hello, World)

int main()
{
  const char arr[10] = {2, 4, 6, 8, '\0', '\0', '\0', '\0', '\0', '\0'};
  {
    char const (&__range1)[10] = arr;
    const char * __begin1 = __range1;
    const char * __end1 = __range1 + 10L;
    for(; __begin1 != __end1; ++__begin1) 
    {
      const char & c = *__begin1;
      printf("c=%c\n", static_cast<int>(c));
    }
    
  }
  std::operator<<(std::operator<<(std::operator<<(std::operator<<(std::cout, (operator+(Word::Hello))._to_string()), ", "), (operator+(Word::World))._to_string()), "!").operator<<(std::endl);
}

I'm exploring a library better-enums and I'd like to see what the BETTER_ENUM macro looks like when it expanded for the compiler, but Cppinsights' macro expansion doesn't work for it, although it works fine for ARR_SIZE macro.

I guess because the BETTER_ENUM macro is too complex, will there be plans to support complex macro expansion?


And is there a way to directly include an online url like Godbold? So that users no longer need to add library code manually.

#include <https://raw.githubusercontent.com/aantron/better-enums/master/enum.h>

❤️ Thank you for the great site!

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