bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.48k stars 581 forks source link

fix: std::char_traits is deprecated for other type than char #748

Closed Clement-Devevey closed 2 months ago

Clement-Devevey commented 6 months ago

Issue was the following:

`jniNativeLibrary.cpp:314:57: warning: 'char_traits' is deprecated: char_traits for T not equal to char, wchar_t, char8_t, char16_t or char32_t is non-standard and is provided for a temporary period. It will be removed in LLVM 18, so please migrate off of it. [-Wdeprecated-declarations] return JavaCPP_createStringFromUTF16(env, ptr, std::char_traits::length(ptr)); ^ char_traits.h:79:8: note: 'char_traits' has been explicitly marked deprecated here struct _LIBCPPDEPRECATED("char_traits for T not equal to char, wchar_t, char8_t, char16_t or char32_t is non-standard and is provided for a temporary period. It will be removed in LLVM 18, so please migrate off of it.") ^ c++/v1/__config:772:53: note: expanded from macro '_LIBCPPDEPRECATED'

define _LIBCPPDEPRECATED(m) attribute((deprecated(m)))`

Clement-Devevey commented 6 months ago

Or
return JavaCPP_createStringFromUTF16(env, ptr, std::char_traits<char16_t>::length(reinterpret_cast<const char16_t*>(ptr))); not sure what's best

saudet commented 6 months ago

That doesn't sound like a correct fix. We need to know the length of the string in UTF-16.

char16_t is only available since C++11, so we need to use something else.

saudet commented 6 months ago

Maybe we could just put an ifdef else endif in there that uses char16_t for C++11 compilers and keep using unsigned short if not?

saudet commented 2 months ago

@Clement-Devevey Since we've decided to make C++11 a requirement for future versions of JavaCPP, let's just replace unsigned short with char16_t. Thanks!

Clement-Devevey commented 2 months ago

@Clement-Devevey Since we've decided to make C++11 a requirement for future versions of JavaCPP, let's just replace unsigned short with char16_t. Thanks!

what an exciting news, thanks a lot :)

saudet commented 2 months ago

You'll open another PR with the change?

saudet commented 1 month ago

Duplicate of #753