Skip to content
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

[libc++][Android] Restrict use of mblen/towctrans/wctrans #116147

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

Conversation

rprichard
Copy link
Contributor

These functions weren't added until API 26 (Android 8.0), but libc++ is supported for API 21 and up.

These APIs are undeclared as of r.android.com/3216959.

These functions weren't added until API 26 (Android 8.0), but libc++ is
supported for API 21 and up.

These APIs are undeclared as of r.android.com/3216959.
@rprichard rprichard requested a review from a team as a code owner November 14, 2024 02:34
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2024

@llvm/pr-subscribers-libcxx

Author: Ryan Prichard (rprichard)

Changes

These functions weren't added until API 26 (Android 8.0), but libc++ is supported for API 21 and up.

These APIs are undeclared as of r.android.com/3216959.


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

4 Files Affected:

  • (modified) libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp (+3)
  • (modified) libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp (+3)
  • (modified) libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp (+3)
  • (modified) libcxx/test/std/strings/c.strings/cwctype.pass.cpp (+3)
diff --git a/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
index 587c6b6e10ddb6..8199fabe3d1a68 100644
--- a/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
@@ -141,7 +141,10 @@ int main(int, char**) {
     wchar_t* pw = 0;
     const wchar_t* pwc = 0;
     char* pc = 0;
+    // mblen was added in Android API 26.
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
     ASSERT_SAME_TYPE(int,    decltype(mblen("",0)));
+#endif
     ASSERT_SAME_TYPE(int,    decltype(mbtowc(pw,"",0)));
     ASSERT_SAME_TYPE(int,    decltype(wctomb(pc,L' ')));
     ASSERT_SAME_TYPE(size_t, decltype(mbstowcs(pw,"",0)));
diff --git a/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp
index 35b294532b2bd2..ebbec565c1ab7d 100644
--- a/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp
@@ -109,5 +109,8 @@ ASSERT_SAME_TYPE(int,       decltype(iswctype(w, wct)));
 ASSERT_SAME_TYPE(wctype_t,  decltype(wctype("")));
 ASSERT_SAME_TYPE(wint_t,    decltype(towlower(w)));
 ASSERT_SAME_TYPE(wint_t,    decltype(towupper(w)));
+// towctrans and wctrans were added in Android API 26.
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
 ASSERT_SAME_TYPE(wint_t,    decltype(towctrans(w, wctr)));
 ASSERT_SAME_TYPE(wctrans_t, decltype(wctrans("")));
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
index a1f7e1143a1e9b..5f33c72f85bfbe 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
@@ -141,7 +141,10 @@ int main(int, char**)
     wchar_t* pw = 0;
     const wchar_t* pwc = 0;
     char* pc = 0;
+    // mblen was added in Android API 26.
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
     static_assert((std::is_same<decltype(std::mblen("",0)), int>::value), "");
+#endif
     static_assert((std::is_same<decltype(std::mbtowc(pw,"",0)), int>::value), "");
     static_assert((std::is_same<decltype(std::wctomb(pc,L' ')), int>::value), "");
     static_assert((std::is_same<decltype(std::mbstowcs(pw,"",0)), std::size_t>::value), "");
diff --git a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp
index 5bc2531d6f6ac7..7460c36c357e7f 100644
--- a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp
+++ b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp
@@ -111,8 +111,11 @@ int main(int, char**) {
   ASSERT_SAME_TYPE(std::wctype_t, decltype(std::wctype("")));
   ASSERT_SAME_TYPE(std::wint_t, decltype(std::towlower(w)));
   ASSERT_SAME_TYPE(std::wint_t, decltype(std::towupper(w)));
+  // towctrans and wctrans were added in Android API 26.
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
   ASSERT_SAME_TYPE(std::wint_t, decltype(std::towctrans(w, std::wctrans_t())));
   ASSERT_SAME_TYPE(std::wctrans_t, decltype(std::wctrans("")));
+#endif
 
   return 0;
 }

Copy link

github-actions bot commented Nov 14, 2024

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

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.

I'm fine with this, but I'd like @ldionne to approve as well.

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