Skip to content
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
3 changes: 3 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 _Returns_twice
#define _Returns_twice [[gnu::returns_twice]]

Copy link
Contributor

Choose a reason for hiding this comment

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

given that this is on both sides of the #ifdef __cplusplus branch is there a way we can unify it instead of having two copies? Also is there a reason you used the gnu attribute instead of the generic one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. returns_twice needs to be namespaced (https://en.cppreference.com/w/cpp/language/attributes.html)
❯ clang test.c                                                               
test.c:3:3: warning: unknown attribute 'returns_twice' ignored [-Wunknown-attributes]
    3 | [[returns_twice]] int f() {
      |   ^~~~~~~~~~~~~
1 warning generated.
  1. [[attribute]] syntax is only supported in C++11. It seems to compile for older versions and this has even been back-ported to C code in clang. I'll push an update to unify this.

Copy link
Member

@petrhosek petrhosek Aug 17, 2025

Choose a reason for hiding this comment

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

The [[attribute]] syntax was only introduced in C20 so we shouldn't be using it in C code since we want our headers are compatible with older C standards.

Copy link
Contributor Author

@saturn691 saturn691 Aug 18, 2025

Choose a reason for hiding this comment

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

Good point, I've settled with preferring to generate the new attribute syntax if the compiler supports it (C++11) onwards.

// This macro serves as a generic cast implementation for use in both C and C++,
// similar to `__BIONIC_CAST` in Android.
#undef __LLVM_LIBC_CAST
Expand Down
Loading