Neargye / magic_enum

Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
MIT License
4.8k stars 429 forks source link

Aliased enums behaving oddly #36

Closed SoylentGraham closed 4 years ago

SoylentGraham commented 4 years ago

From the limitations, I see that aliases don't work, this would be fine, but I seem to be getting an odd case where the first-use of a value, is NOT the one used, furthermore, I'm getting 0x0 for a string, instead of the alias. (Either in my case would be fine, but not an empty string)

THEN, debugging in vs17, when I look at the strings table (which I guess is all the names baked into an array) my values START at 128 instead of 0 this is the enum https://github.com/SoylentGraham/SoyLib/blob/master/src/SoyPixels.h#L22 enum strings

I've been using this library for a while now without problems, even with this enum, so perhaps I've just missed this case, or in this particular code I'm using it in a strange way... (still investigating :)

Neargye commented 4 years ago

Hi @SoylentGraham, thanks for issues. It looks very strange, could you please give your compilation flags?

SoylentGraham commented 4 years ago

/JMC /permissive- /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"D:\PopCap\PopCap.visualstudio\PopCap_x64_Debug\Temp\vc141.pdb" /Zc:inline /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MTd /FC /Fa"D:\PopCap\PopCap.visualstudio\PopCap_x64_Debug\Temp\" /EHsc /nologo /Fo"D:\PopCap\PopCap.visualstudio\PopCap_x64_Debug\Temp\" /Fp"D:\PopCap\PopCap.visualstudio\PopCap_x64_Debug\Temp\PopCap.pch" /diagnostics:classic Let me know if something like the verbose build output of visual studio will be more useful (Also that looks like I'm using a PCH, but definitely not!)

Back on osx today, so will see if I have the same problems, but pretty sure I don't (probably why I only just started seeing it go wrong)

I'll also find time to do a minimal repro

SoylentGraham commented 4 years ago

Also note: I'm using the latest (I was a bit behind, but updating to master made no difference)

SoylentGraham commented 4 years ago

Seems to be fine in xcode (CLANG_CXX_LANGUAGE_STANDARD = gnu++14)

Neargye commented 4 years ago

@SoylentGraham It looks like the behavior of aliases has broken on vs17, but is correct on vs19.

I’m still investigating this problem, but it seems necessary to add to the documentation that the order with aliases is undefined.

SoylentGraham commented 4 years ago

Is the undefined order causing the empty strings? or is that a side effect? (In my case, I don't mind which comes up, but null strings are a problem)

Neargye commented 4 years ago

Unfortunately, yes, adding aliases occur empty strings, because the compiler cannot output either the actual value or the alias.

I can offer such a workaround

enum Type {
  Invalid = 0,
  Greyscale,
  ...
};

enum Aliases {
  Luma_Full = Greyscale,
  Nv12 = Yuv_8_88_Full,
  Nv21 = Yvu_8_88_Ntsc,
  I420 = Yuv_8_8_8_Full,
};
Neargye commented 4 years ago

https://developercommunity.visualstudio.com/content/problem/734005/-funcsig-doesnt-resolve-non-type-template-paramete.html

SoylentGraham commented 4 years ago

I thought this wasn't a bug in 2019?

Is it still broken in 2017?

On Sun, 31 May 2020 at 1:14 pm, Daniil Goncharov notifications@github.com wrote:

Closed #36 https://github.com/Neargye/magic_enum/issues/36.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Neargye/magic_enum/issues/36#event-3390555589, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQVIBLGNOQDTV37TGELK4LRUJC3FANCNFSM4MY6KFJQ .

--

Neargye commented 4 years ago

@SoylentGraham In 2019, it works correctly. In 2017, unfortunately, with aliasing of enums, its has broken.