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.99k stars 445 forks source link

Fails to build with `-DMAGIC_ENUM_OPT_ENABLE_NONASCII=ON` or `-DMAGIC_ENUM_OPT_BUILD_TESTS=ON`: `extended character 😃 is not valid in an identifier`. #244

Closed dreirund closed 1 year ago

dreirund commented 1 year ago

When I build with the following options to cmake:

cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr \
  -DMAGIC_ENUM_OPT_BUILD_EXAMPLES=ON \
  -DMAGIC_ENUM_OPT_BUILD_TESTS=ON \
  -DMAGIC_ENUM_OPT_ENABLE_NONASCII=ON \

make errors out with error messages like "extended character 😃 is not valid in an identifier":

[ 30%] Building CXX object example/CMakeFiles/example_nonascii_name.dir/example_nonascii_name.cpp.o
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/example/example_nonascii_name.cpp:32:5: error: extended character 😃 is not valid in an identifier
   32 |     😃 = 40,
      |     ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/example/example_nonascii_name.cpp:39:48: error: extended character 😃 is not valid in an identifier
   39 |   std::cout << magic_enum::enum_name(Language::😃) << std::endl; // Emoji
      |                                                ^
[ 32%] Linking CXX executable example_containers_set
[ 35%] Linking CXX executable example_custom_name
[ 35%] Built target example_containers_set
make[2]: *** [example/CMakeFiles/example_nonascii_name.dir/build.make:76: example/CMakeFiles/example_nonascii_name.dir/example_nonascii_name.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:334: example/CMakeFiles/example_nonascii_name.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 37%] Building CXX object test/CMakeFiles/test-cpp17.dir/test.cpp.o
[ 37%] Built target example_custom_name
[ 40%] Linking CXX executable example_switch
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:54:69: error: extended character 😃 is not valid in an identifier
   54 | enum class Language : int { 日本語 = 10, 한국어 = 20, English = 30, 😃 = 40 };
      |                                                                     ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:140:60: error: extended character 😃 is not valid in an identifier
  140 |     REQUIRE(enum_cast<Language>("😃").value() == Language::😃);
      |                                                            ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:194:58: error: extended character 😃 is not valid in an identifier
  194 |     REQUIRE(enum_cast<Language>(40).value() == Language::😃);
      |                                                          ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:239:36: error: extended character 😃 is not valid in an identifier
  239 |     REQUIRE(enum_integer(Language::😃) == 40);
      |                                    ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:286:34: error: extended character 😃 is not valid in an identifier
  286 |     REQUIRE(enum_index(Language::😃) == 3);
      |                                  ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:332:37: error: extended character 😃 is not valid in an identifier
  332 |     REQUIRE(enum_contains(Language::😃));
      |                                     ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:371:47: error: extended character 😃 is not valid in an identifier
  371 |     REQUIRE(enum_contains<Language>(Language::😃));
      |                                               ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:472:31: error: extended character 😃 is not valid in an identifier
  472 |     REQUIRE(lang == Language::😃);
      |                               ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:511:107: error: extended character 😃 is not valid in an identifier
  511 |   REQUIRE(s7 == std::array<Language, 4>{{Language::日本語, Language::한국어, Language::English, Language::😃}});
      |                                                                                                           ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:575:33: error: extended character 😃 is not valid in an identifier
  575 |     REQUIRE(enum_name(Language::😃) == "😃");
      |                                 ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:618:33: error: extended character 😃 is not valid in an identifier
  618 |     REQUIRE(enum_name<Language::😃>() == "😃");
      |                                 ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:671:174: error: extended character 😃 is not valid in an identifier
  671 | r<Language, std::string_view>, 4>{{{Language::日本語, "日本語"}, {Language::한국어, "한국어"}, {Language::English, "English"}, {Language::😃, "😃"}}});
      |                                                                                                                                           ^

/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:708:26: error: extended character 😃 is not valid in an identifier
  708 |   test_ostream(Language::😃, "😃");
      |                          ^
/home/[...]/.cache/yay/magic_enum-git/src/magic_enum/test/test.cpp:744:26: error: extended character 😃 is not valid in an identifier
  744 |   test_istream(Language::😃, "😃");
      |                          ^
[ 40%] Built target example_switch
make[2]: *** [test/CMakeFiles/test-cpp17.dir/build.make:79: test/CMakeFiles/test-cpp17.dir/test.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:360: test/CMakeFiles/test-cpp17.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

System information:

Regards!

Neargye commented 1 year ago

Fixed in https://github.com/Neargye/magic_enum/pull/261