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

llama : C++20 compatibility for u8 strings #8408

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

iboB
Copy link
Contributor

@iboB iboB commented Jul 10, 2024

This PR fixes the compilation errors when compiling with C++20 (which may come from above incase llama.cpp is a subdir)

In C++20 char8_t is distinct from char. That's why u8"string" (being const char8_t*) cannot be implicitly cast to const char*. The PR adds a macro which performs the explicit cast if necessary

#if __cplusplus >= 202000L
#define LU8(x) (const char*)(u8##x)
#else
#define LU8(x) u8##x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why prefix the macro with L ? , that makes it seem like it is a wide string.

Copy link
Contributor Author

@iboB iboB Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in llama, could be T as well. I wanted three characters to minimize the risk of collisions, as simply U8 looks risky.

@@ -57,6 +57,12 @@
#include <io.h>
#endif

#if __cplusplus >= 202000L
#define LU8(x) (const char*)(u8##x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use a proper cast, instead of a c-style one.

Copy link
Contributor Author

@iboB iboB Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It's not like there are any "proper" casts in the file itself. All other casts are C-style.

@ggerganov ggerganov merged commit cc61948 into ggerganov:master Jul 10, 2024
53 checks passed
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Jul 11, 2024
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Jul 13, 2024
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants