Skip to content

Conversation

@philnik777
Copy link
Contributor

There are a few types without which the library is hopelessly broken. Specifically, these are size_t, ptrdiff_t and the intX_t and uintX_t types. This results in significantly better diagnostics if they are missing, since they are flagged at the using instead of the inevitable first use.

@philnik777 philnik777 requested a review from a team as a code owner September 4, 2024 11:06
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Sep 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2024

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

There are a few types without which the library is hopelessly broken. Specifically, these are size_t, ptrdiff_t and the intX_t and uintX_t types. This results in significantly better diagnostics if they are missing, since they are flagged at the using instead of the inevitable first use.


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

8 Files Affected:

  • (modified) libcxx/include/cstddef (+2-2)
  • (modified) libcxx/include/cstdint (+9-9)
  • (modified) libcxx/include/cstdio (+1-1)
  • (modified) libcxx/include/cstdlib (+1-1)
  • (modified) libcxx/include/cstring (+1-1)
  • (modified) libcxx/include/ctime (+1-1)
  • (modified) libcxx/include/cuchar (+1-1)
  • (modified) libcxx/include/cwchar (+1-1)
diff --git a/libcxx/include/cstddef b/libcxx/include/cstddef
index 592f6261a6de3f..223eab878050e9 100644
--- a/libcxx/include/cstddef
+++ b/libcxx/include/cstddef
@@ -56,8 +56,8 @@ Types:
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::nullptr_t;
-using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::ptrdiff_t;
+using ::size_t;
 
 #if !defined(_LIBCPP_CXX03_LANG)
 using ::max_align_t _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/cstdint b/libcxx/include/cstdint
index 8c4782859426dd..88f6f901f9fd09 100644
--- a/libcxx/include/cstdint
+++ b/libcxx/include/cstdint
@@ -158,15 +158,15 @@ Types:
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-using ::int8_t _LIBCPP_USING_IF_EXISTS;
-using ::int16_t _LIBCPP_USING_IF_EXISTS;
-using ::int32_t _LIBCPP_USING_IF_EXISTS;
-using ::int64_t _LIBCPP_USING_IF_EXISTS;
-
-using ::uint8_t _LIBCPP_USING_IF_EXISTS;
-using ::uint16_t _LIBCPP_USING_IF_EXISTS;
-using ::uint32_t _LIBCPP_USING_IF_EXISTS;
-using ::uint64_t _LIBCPP_USING_IF_EXISTS;
+using ::int8_t;
+using ::int16_t;
+using ::int32_t;
+using ::int64_t;
+
+using ::uint8_t;
+using ::uint16_t;
+using ::uint32_t;
+using ::uint64_t;
 
 using ::int_least8_t _LIBCPP_USING_IF_EXISTS;
 using ::int_least16_t _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/cstdio b/libcxx/include/cstdio
index 7f94371081f8b1..633773e63e5de1 100644
--- a/libcxx/include/cstdio
+++ b/libcxx/include/cstdio
@@ -115,7 +115,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::FILE _LIBCPP_USING_IF_EXISTS;
 using ::fpos_t _LIBCPP_USING_IF_EXISTS;
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::size_t;
 
 using ::fclose _LIBCPP_USING_IF_EXISTS;
 using ::fflush _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/cstdlib b/libcxx/include/cstdlib
index c817fd8f4accda..e57a54e38a97f8 100644
--- a/libcxx/include/cstdlib
+++ b/libcxx/include/cstdlib
@@ -99,7 +99,7 @@ void *aligned_alloc(size_t alignment, size_t size);                       // C11
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::size_t;
 using ::div_t _LIBCPP_USING_IF_EXISTS;
 using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
 using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/cstring b/libcxx/include/cstring
index c2c92b02e73cc1..268ec1e8fabd8a 100644
--- a/libcxx/include/cstring
+++ b/libcxx/include/cstring
@@ -75,7 +75,7 @@ size_t strlen(const char* s);
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::size_t;
 using ::memcpy _LIBCPP_USING_IF_EXISTS;
 using ::memmove _LIBCPP_USING_IF_EXISTS;
 using ::strcpy _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/ctime b/libcxx/include/ctime
index f47b49a43e23ef..b1124ad0eb489d 100644
--- a/libcxx/include/ctime
+++ b/libcxx/include/ctime
@@ -62,7 +62,7 @@ int timespec_get( struct timespec *ts, int base); // C++17
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::clock_t _LIBCPP_USING_IF_EXISTS;
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::size_t;
 using ::time_t _LIBCPP_USING_IF_EXISTS;
 using ::tm _LIBCPP_USING_IF_EXISTS;
 #if _LIBCPP_STD_VER >= 17
diff --git a/libcxx/include/cuchar b/libcxx/include/cuchar
index f0015be275367d..9ffc5548c1c7f4 100644
--- a/libcxx/include/cuchar
+++ b/libcxx/include/cuchar
@@ -57,7 +57,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 #if !defined(_LIBCPP_CXX03_LANG)
 
 using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::size_t;
 
 #  if !defined(_LIBCPP_HAS_NO_C8RTOMB_MBRTOC8)
 using ::mbrtoc8 _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/cwchar b/libcxx/include/cwchar
index 08cfac58c846ac..9bbb19d5f00f35 100644
--- a/libcxx/include/cwchar
+++ b/libcxx/include/cwchar
@@ -127,7 +127,7 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
-using ::size_t _LIBCPP_USING_IF_EXISTS;
+using ::size_t;
 using ::tm _LIBCPP_USING_IF_EXISTS;
 using ::wint_t _LIBCPP_USING_IF_EXISTS;
 using ::FILE _LIBCPP_USING_IF_EXISTS;

@github-actions
Copy link

github-actions bot commented Sep 4, 2024

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

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.

This makes sense to me for ptrdiff_t, size_t and nullptr_t, but not for the optional types like int8_t. Also this should be rebased on top of the new __cstddef headers.

@ldionne ldionne force-pushed the remove_using_if_exists branch from 4c1dc3f to 29445fa Compare September 13, 2024 13:31
@ldionne
Copy link
Member

ldionne commented Sep 13, 2024

@philnik777 I rebased the patch and applied my comments, and I also dropped using_if_exists from max_align_t. Please let me know what you think of the patch now -- I'd be fine to land as-is.

If you land, please remember to update the PR description first so it reflects what the new version of the patch does.

@philnik777
Copy link
Contributor Author

This is superseded by #114788.

@philnik777 philnik777 closed this Nov 5, 2024
@philnik777 philnik777 deleted the remove_using_if_exists branch November 5, 2024 15:21
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.

3 participants