Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[libc++] Add a missing include in string.h #135134

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

atetubou
Copy link
Contributor

stddef.h is necessary for size_t in explicit Clang modules build.

`stddef.h` is necessary for `size_t`.
@atetubou atetubou requested a review from a team as a code owner April 10, 2025 06:33
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Apr 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-libcxx

Author: Takuto Ikuta (atetubou)

Changes

stddef.h is necessary for size_t in explicit Clang modules build.


Full diff: https://github.com/llvm/llvm-project/pull/135134.diff

1 Files Affected:

  • (modified) libcxx/include/string.h (+2)
diff --git a/libcxx/include/string.h b/libcxx/include/string.h
index 6bdcd6a6eecbd..c61fda32d76f8 100644
--- a/libcxx/include/string.h
+++ b/libcxx/include/string.h
@@ -64,6 +64,8 @@ size_t strlen(const char* s);
 #    include_next <string.h>
 #  endif
 
+#  include <stddef.h> 
+
 // MSVCRT, GNU libc and its derivates may already have the correct prototype in
 // <string.h>. This macro can be defined by users if their C library provides
 // the right signature.

Copy link

github-actions bot commented Apr 10, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -64,6 +64,8 @@ size_t strlen(const char* s);
# include_next <string.h>
# endif

# include <stddef.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

How about including <__cstddef/size_t.h> which looks smaller?

Suggested change
# include <stddef.h>
# include <__cstddef/size_t.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As this file uses bare size_t instead of std::size_t, I think <stddef.h> is a corret header to include here.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, I don't think we can use __cstddef/size_t.h because it doesn't provide the right declaration (conceptually). In practice, of course, they're all the same type in the end.

This makes me wonder whether we should introduce an internal alias for decltype(sizeof(int)), something like __libcxx_size_t and then do namespace std { using size_t = ::__libcxx_size_t; }. However, until we have a reason to do that, I think including <stddef.h> here is fine.

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

Do you have a reproducer?

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

We can tell by inspection that we have a missing include, so IMO this change is fine. IIUC a reproducer is going to exist once we start being able to build libc++ with explicit modules.

@@ -64,6 +64,8 @@ size_t strlen(const char* s);
# include_next <string.h>
# endif

# include <stddef.h>
Copy link
Member

Choose a reason for hiding this comment

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

I agree, I don't think we can use __cstddef/size_t.h because it doesn't provide the right declaration (conceptually). In practice, of course, they're all the same type in the end.

This makes me wonder whether we should introduce an internal alias for decltype(sizeof(int)), something like __libcxx_size_t and then do namespace std { using size_t = ::__libcxx_size_t; }. However, until we have a reason to do that, I think including <stddef.h> here is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants