llohse / libnpy

C++ library for reading and writing of numpy's .npy files
MIT License
361 stars 72 forks source link

[clang] constexpr variable cannot have non-literal type #14

Closed apivovarov closed 3 years ago

apivovarov commented 3 years ago

Any plans to make it compatible with clang?

Problematic line: https://github.com/llohse/libnpy/blob/master/npy.hpp#L67

-- Check for working C compiler: /root/workspace/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /root/workspace/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works

-- Check for working CXX compiler: /root/workspace/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /root/workspace/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works

/root/workspace/neo-ai-dlr/3rdparty/libnpy/npy.hpp:66:30: error: constexpr variable cannot have non-literal type 'const std::array<char, 3>'
constexpr std::array<char,3> endian_chars = { little_endian_char, big_endian_char, no_endian_char };
                             ^
/root/workspace/neo-ai-dlr/3rdparty/libnpy/npy.hpp:66:30: error: implicit instantiation of undefined template 'std::__ndk1::array<char, 3>'
/root/workspace/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__tuple:223:64: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
                                                               ^
In file included from /root/workspace/neo-ai-dlr/demo/cpp/run_resnet.cc:16:
/root/workspace/neo-ai-dlr/3rdparty/libnpy/npy.hpp:67:30: error: constexpr variable cannot have non-literal type 'const std::array<char, 4>'
constexpr std::array<char,4> numtype_chars = { 'f', 'i', 'u', 'c' };
                             ^
/root/workspace/neo-ai-dlr/3rdparty/libnpy/npy.hpp:67:30: error: implicit instantiation of undefined template 'std::__ndk1::array<char, 4>'
/root/workspace/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__tuple:223:64: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;

More on the issue: https://stackoverflow.com/questions/46576847/clang-vs-gcc-crtp-constexpr-variable-cannot-have-non-literal-type

C++ named requirements: LiteralType: https://en.cppreference.com/w/cpp/named_req/LiteralType

llohse commented 3 years ago

Thank you for reporting this. However, I do not quite understand the problem yet.. According to https://en.cppreference.com/w/cpp/named_req/LiteralType, arrays should be allowed. I will look into it.

llohse commented 3 years ago

@apivovarov: could you try replacing

constexpr std::array<char,3> endian_chars = { little_endian_char, big_endian_char, no_endian_char };
constexpr std::array<char,4> numtype_chars = { 'f', 'i', 'u', 'c' };

with

constexpr std::array<char,3> endian_chars {{ little_endian_char, big_endian_char, no_endian_char }};
constexpr std::array<char,4> numtype_chars {{ 'f', 'i', 'u', 'c' }};

and see if that works for you?

apivovarov commented 3 years ago

ok, I used old version 641f2a5 The issue was already fixed here https://github.com/llohse/libnpy/commit/3e0e373828d88b0a1df2ba73cc31616a848b1aef Sorry for false alarm

llohse commented 3 years ago

Thanks for the clarification. Maybe I should start to use version numbers...