fmt icon indicating copy to clipboard operation
fmt copied to clipboard

Use of all-caps macro-style names for enum members collides with macros

Open ogrant opened this issue 8 years ago • 7 comments

Hi,

The Type enum defined in format.h uses all uppercase names for its members which easily collides with macro names, especially as those names are commonly used by C libraries:

  enum Type {
    NONE, NAMED_ARG,
    // Integer types should go first,
    INT, UINT, LONG_LONG, ULONG_LONG, BOOL, CHAR, LAST_INTEGER_TYPE = CHAR,
    // followed by floating-point types.
    DOUBLE, LONG_DOUBLE, LAST_NUMERIC_TYPE = LONG_DOUBLE,
    CSTRING, STRING, WSTRING, POINTER, CUSTOM
  };

Great library btw.

Thanks,

O.

ogrant avatar Feb 08 '18 22:02 ogrant

Did you have a collision with any specific name? Normally it's easy to fix this by ordering includes but I'm open to changing some names if there are collisions with a widely used C library.

vitaut avatar Feb 10 '18 23:02 vitaut

@vitaut Are these constants for users? If not I'd rather either convert them to enum class if you are targeting C++11 or put them into a detail namespace.

t-b avatar Feb 10 '18 23:02 t-b

@t-b They are already in the internal namespace, but the question here is collision with global macros.

vitaut avatar Feb 11 '18 00:02 vitaut

I see collisions as well, up until now I have modified locally the names to have a FMT_ prefix. In particular LONG_LONG has been a culprit. (I sent a patch that fixes it in the way that we have done internally, you might want to do something else.)

LarsGullik avatar Feb 16 '18 12:02 LarsGullik

Sorry for not getting back to you earlier.

I think in this particular case, it was ruby.h, which is probably not very popular.

But independently from that, I would humbly argue that giving C++ enums all caps names, especially one as common as LONG_LONG which is used in many C libs is just asking for trouble. I would suggest moving to a more C++ naming convension (eName or kName), or basically anything else than all caps.

ogrant avatar Feb 16 '18 13:02 ogrant

Fixed in https://github.com/fmtlib/fmt/commit/8ed264fcd49de5716204e77c6293e1a7aef46906.

vitaut avatar Feb 16 '18 17:02 vitaut

Thanks!

ogrant avatar Feb 16 '18 17:02 ogrant