Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compilation error when using with another library #1577

Closed
bl4ck5un opened this issue Apr 21, 2019 · 6 comments
Closed

compilation error when using with another library #1577

bl4ck5un opened this issue Apr 21, 2019 · 6 comments

Comments

@bl4ck5un
Copy link

  • What is the issue you have?

To be honest, I'm not sure if this is a bug in this library, as it only happens when used together with another library, and only on macOS. But I'd appreciate any insight the authors might have. The error message appears agnostic to the other library in question.

/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:12450:106: error: no matching member function for call to 'to_char_type'
                                    string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xEF');
                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:12117:25: note: in instantiation of member function 'nlohmann::detail::serializer<nlohmann::basic_json<std::map, std::vector,
      std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> >::dump_escaped' requested here
                        dump_escaped(i->first, ensure_ascii);
                        ^
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:14744:15: note: in instantiation of member function 'nlohmann::detail::serializer<nlohmann::basic_json<std::map, std::vector,
      std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> >::dump' requested here
            s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));
              ^
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:20743:20: note: in instantiation of member function 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long
      long, unsigned long long, double, std::allocator, adl_serializer>::dump' requested here
        return h(j.dump());
                   ^
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:10843:31: note: candidate template ignored: substitution failure [with C = char]: null non-type template argument must be cast to
      template parameter type 'enable_if_t<std::is_signed<char>::value && std::is_signed<char>::value> *' (aka 'void *')
    static constexpr CharType to_char_type(std::uint8_t x) noexcept
                              ^
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:10850:21: note: candidate template ignored: requirement 'std::is_unsigned<char>::value' was not satisfied [with C = char]
    static CharType to_char_type(std::uint8_t x) noexcept
                    ^
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:10861:31: note: candidate template ignored: requirement 'std::is_unsigned<char>::value' was not satisfied [with C = char]
    static constexpr CharType to_char_type(std::uint8_t x) noexcept
                              ^
/Users/fanz/dev/deco/notary/external/json/single_include/nlohmann/json.hpp:10872:31: note: candidate template ignored: substitution failure [with InputCharType = char, C = char]: null non-type template argument
      must be cast to template parameter type 'enable_if_t<std::is_signed<char>::value && std::is_signed<char>::value && std::is_same<char, typename std::remove_cv<char>::type>::value> *' (aka 'void *')
    static constexpr CharType to_char_type(InputCharType x) noexcept
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

In my case, as long as https://github.com/unbound-tech/blockchain-crypto-mpc/blob/master/src/utils/ub_common_def.h is included along with json.hpp, the compilation would fail.

Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • Did you use a released version of the library or the version from the develop branch?

v3.6.1 is used.

@bl4ck5un bl4ck5un changed the title compilation error when using another library compilation error when using with another library Apr 21, 2019
@Macr0Nerd
Copy link
Contributor

@nlohmann or @theodelrieu correct me if I'm wrong, but it seems that there is some interference with to_char, presumably from the other library. It looks like one of the characters being input isn't being read as char.

@Macr0Nerd
Copy link
Contributor

@bl4ck5un can you provide an example of what you input and where the supposed error is?

@bl4ck5un
Copy link
Author

bl4ck5un commented May 1, 2019

never mind guys, it's a messy project and hard to extract a small example. I can work it around by arranging the header carefully. Will reopen with a reproducible example when I have one. Thanks anyway.

@bl4ck5un bl4ck5un closed this as completed May 1, 2019
@x-santiaga-x
Copy link

x-santiaga-x commented Dec 1, 2020

The compilation error is caused by nullptr has been defined as 0 in ub_common_def.h when compiling with clang.

#if defined(__GNUC__) && (GCC_VERSION < 0x0406) // 4.6
#define nullptr NULL
#endif

clang defines GNUC/MINOR/PATCHLEVEL as 4/2/1, i.e. compat with GCC 4.2.1.

Correct gcc version check could be
#if !defined(__clang__) && defined(__GNUC__) && (GCC_VERSION < 0x0406) // 4.6

So it might be helpful to insert some nullptr type checking with static_assert.

@gregmarr
Copy link
Contributor

gregmarr commented Dec 1, 2020

@x-santiaga-x Did you mean to submit this report to the library containing ub_common_def.h?

@x-santiaga-x
Copy link

I have discovered this error trying to compile my own project with the same #ifdef and it was hard to find.
Adding a static assertion can keep users from researching what no matching member function for call to 'to_char_type' might mean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants