-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
base: main
Are you sure you want to change the base?
Conversation
`stddef.h` is necessary for `size_t`.
@llvm/pr-subscribers-libcxx Author: Takuto Ikuta (atetubou) Changes
Full diff: https://github.com/llvm/llvm-project/pull/135134.diff 1 Files Affected:
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.
|
✅ 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> |
There was a problem hiding this comment.
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?
# include <stddef.h> | |
# include <__cstddef/size_t.h> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
There was a problem hiding this 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> |
There was a problem hiding this comment.
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.
stddef.h
is necessary forsize_t
in explicit Clang modules build.