zauguin / i18n-cpp

MIT License
39 stars 6 forks source link

Cannot use the library with Apple Clang 13 (clang-1300.0.29.30) #3

Closed viniciusferrao closed 2 years ago

viniciusferrao commented 2 years ago

Hello, I'm trying to use library in a project but it seems that something from is missing on macOS:

/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:66:18: error: no template named 'convertible_to' in namespace 'std' template <std::convertible_to First, typename... Args>

This happens with Apple clang on macOS Monterey 12.2.1 (latest version as today)

❯ clang --version
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Also there's a lot of warnings that I'm not sure if it's relevant or not:

====================[ Build | main | Debug ]==================================== /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/ferrao/Documents/Development/cloyster/cmake-build-debug --target main -- -j 12 Consolidate compiler generated dependencies of target main [ 3%] Building CXX object src/CMakeFiles/main.dir/main.cpp.o In file included from /Users/ferrao/Documents/Development/cloyster/src/main.cpp:25: In file included from /Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:4: In file included from /Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:4: /Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:48:41: warning: implicit conversion changes signedness: 'int' to 'const std::size_t' (aka 'const unsigned long') [-Wsign-conversion] static constexpr std::size_t length = -1;


/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:89:9: warning: unknown attribute 'i18n' ignored [-Wunknown-attributes]
class [[mfk::i18n]] CompileTimeI18NString {
        ^~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:106:40: warning: unknown attribute 'i18n_domain_begin' ignored [-Wunknown-attributes]
  static constexpr auto domain_begin [[mfk::i18n_domain_begin]] =
                                       ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:108:38: warning: unknown attribute 'i18n_domain_end' ignored [-Wunknown-attributes]
  static constexpr auto domain_end [[mfk::i18n_domain_end]] =
                                     ^~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:110:53: warning: unknown attribute 'i18n_context_begin' ignored [-Wunknown-attributes]
  static constexpr const char_type *context_begin [[mfk::i18n_context_begin]] =
                                                    ^~~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:112:51: warning: unknown attribute 'i18n_context_end' ignored [-Wunknown-attributes]
  static constexpr const char_type *context_end [[mfk::i18n_context_end]] =
                                                  ^~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:114:54: warning: unknown attribute 'i18n_singular_begin' ignored [-Wunknown-attributes]
  static constexpr const char_type *singular_begin [[mfk::i18n_singular_begin]] =
                                                     ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:116:52: warning: unknown attribute 'i18n_singular_end' ignored [-Wunknown-attributes]
  static constexpr const char_type *singular_end [[mfk::i18n_singular_end]] =
                                                   ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:118:52: warning: unknown attribute 'i18n_plural_begin' ignored [-Wunknown-attributes]
  static constexpr const char_type *plural_begin [[mfk::i18n_plural_begin]] =
                                                   ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n/base.hpp:120:50: warning: unknown attribute 'i18n_plural_end' ignored [-Wunknown-attributes]
  static constexpr const char_type *plural_end [[mfk::i18n_plural_end]] =
                                                 ^~~~~~~~~~~~~~~~~~~~
In file included from /Users/ferrao/Documents/Development/cloyster/src/main.cpp:25:
In file included from /Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:4:
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:66:18: error: no template named 'convertible_to' in namespace 'std'
  template <std::convertible_to<unsigned long> First, typename... Args>
            ~~~~~^
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:67:29: error: unknown type name 'First'
  decltype(auto) operator()(First &&first, Args &&...args) const {
                            ^
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:365:24: warning: implicit conversion changes signedness: 'int' to 'std::size_t' (aka 'unsigned long') [-Wsign-conversion]
          try_plural = -1;
                     ~ ^~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:386:22: warning: implicit conversion changes signedness: 'int' to 'std::size_t' (aka 'unsigned long') [-Wsign-conversion]
        try_plural = -1;
                   ~ ^~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:430:29: warning: implicit conversion changes signedness: 'int' to 'std::size_t' (aka 'unsigned long') [-Wsign-conversion]
      std::size_t context = -1, singular = 0, plural = -1;
                          ~ ^~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/../i18n.hpp:430:56: warning: implicit conversion changes signedness: 'int' to 'std::size_t' (aka 'unsigned long') [-Wsign-conversion]
      std::size_t context = -1, singular = 0, plural = -1;
                                                     ~ ^~
In file included from /Users/ferrao/Documents/Development/cloyster/src/main.cpp:25:
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:7:38: warning: unknown attribute 'i18n_singular_begin' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *gettext([[mfk::i18n_singular_begin]] const char *);
                                     ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:7:3: warning: unknown attribute 'i18n' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *gettext([[mfk::i18n_singular_begin]] const char *);
  ^~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:8:39: warning: unknown attribute 'i18n_domain_begin' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *dgettext([[mfk::i18n_domain_begin]] const char *,
                                      ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:9:39: warning: unknown attribute 'i18n_singular_begin' ignored [-Wunknown-attributes]
                                    [[mfk::i18n_singular_begin]] const char *);
                                      ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:8:3: warning: unknown attribute 'i18n' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *dgettext([[mfk::i18n_domain_begin]] const char *,
  ^~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:10:39: warning: unknown attribute 'i18n_singular_begin' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *ngettext([[mfk::i18n_singular_begin]] const char *,
                                      ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:11:39: warning: unknown attribute 'i18n_plural_begin' ignored [-Wunknown-attributes]
                                    [[mfk::i18n_plural_begin]] const char *, unsigned long);
                                      ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:10:3: warning: unknown attribute 'i18n' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *ngettext([[mfk::i18n_singular_begin]] const char *,
  ^~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:12:40: warning: unknown attribute 'i18n_domain_begin' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *dngettext([[mfk::i18n_domain_begin]] const char *,
                                       ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:13:40: warning: unknown attribute 'i18n_singular_begin' ignored [-Wunknown-attributes]
                                     [[mfk::i18n_singular_begin]] const char *,
                                       ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:14:40: warning: unknown attribute 'i18n_plural_begin' ignored [-Wunknown-attributes]
                                     [[mfk::i18n_plural_begin]] const char *, unsigned long);
                                       ^~~~~~~~~~~~~~~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:12:3: warning: unknown attribute 'i18n' ignored [-Wunknown-attributes]
[[mfk::i18n]] extern char *dngettext([[mfk::i18n_domain_begin]] const char *,
  ^~~~~~~~~
/Users/ferrao/Documents/Development/cloyster/src/include/i18n-cpp/include/i18n/simple.hpp:19:3: warning: unknown attribute 'i18n' ignored [-Wunknown-attributes]
[[mfk::i18n]] constexpr auto operator""_() {
  ^~~~~~~~~
27 warnings and 2 errors generated.
make[3]: *** [src/CMakeFiles/main.dir/main.cpp.o] Error 1
make[2]: *** [src/CMakeFiles/main.dir/all] Error 2
make[1]: *** [src/CMakeFiles/main.dir/rule] Error 2
make: *** [main] Error 2

There's a way to don't rely on std::convertible_to concept so we can use it on macOS?

Thank you.

zauguin commented 2 years ago

Not sure why this is happening since I looked in the repo and libc++ did include std::convertible_to in 13.0.0, but maybe it's an Apple thing... Anyway I added a polyfill, so please try the latest commit.

About the warnings: Most of them (the -Wunknown-attributes ones) are telling you that the compiler plugin to automatically extract the untranslated strings is not loaded. The library still works, but it doesn't automatically generate POC files then.

I'm not sure if I should suppress these warnings. They are somewhat useful (after all is is rather easy to forget to pass the -fplugin argument) but they are also quite ugly. Maybe I replace them with one more explicit warning instead.

viniciusferrao commented 2 years ago

Hi @zauguin, it worked. Thanks.

After digging on the issue, it seems that Apple does not implements <concepts>. Almost the entire include file is commented out with /* *\.

Here's a copy of what is on my computer: https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX11.3.sdk/usr/include/c++/v1/concepts

Regarding the warnings, I don't have the plugin enabled yet. Still finding my way around the lib, so it will be away when it's properly configured.

Thank you again.

zauguin commented 2 years ago

Looks like libc++ 12 (based on https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX11.3.sdk/usr/include/c%2B%2B/v1/__libcpp_version). At least it implements std::same_as which should be the only other concept the library currently uses.