Skip to content

[libc] add LLVM_LIBC_CAST macro. #127319

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

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libc/include/__llvm-libc-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#define __NOEXCEPT throw()
#endif

#undef LLVM_LIBC_CAST
#define LLVM_LIBC_CAST(cast, type, value) (cast<type>(value))
Copy link
Contributor

Choose a reason for hiding this comment

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

This merits a comment about its intended uses.
No macro should be defined in this file unless it's in the implementation namespace.
Sticking to the __ prefix seems like the best convention, with the exception of the C11 keywords that are in the _[A-Z] part of the implementation namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


#else // not __cplusplus

#undef __BEGIN_C_DECLS
Expand Down Expand Up @@ -85,6 +88,9 @@
#undef _Returns_twice
#define _Returns_twice __attribute__((returns_twice))

#undef LLVM_LIBC_CAST
#define LLVM_LIBC_CAST(cast, type, value) ((type)(value))

#endif // __cplusplus

#endif // LLVM_LIBC_COMMON_H
Loading