boostorg / describe

A C++14 reflection library
https://boost.org/libs/describe
69 stars 24 forks source link

Compile error while trying to use describe on a class named D #3

Closed Julien-Blanc-tgcm closed 3 years ago

Julien-Blanc-tgcm commented 3 years ago

The following code does not compile (g++ version 7-10, linux, -std=c++17 or gnu++14 for gcc7):

struct D {
        int a;
};
BOOST_DESCRIBE_STRUCT(D, (), (a))

It seems that the “D” name is somehow used in describe internals (macros), and as such, reserved. Describe should use longer names, and ideally prefixed one, such as DESCRIBE_INTERNAL_D (and document this) to avoid name clashes.

pdimov commented 3 years ago

Good catch, thanks. I didn't want to use a long name because it's visible in the typeinfo of the descriptor list, but D is obviously unsuitable. I'll probably change it to _desc_ as a compromise. Unfortunately I'm not allowed to use a reserved name such as _D or __desc here, otherwise it would have been ideal.

pdimov commented 3 years ago

Should be fixed now.