[libcxx-commits] [libcxx] [libc++][Android] Restrict use of mblen/towctrans/wctrans (PR #116147)
Ryan Prichard via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 18 14:54:37 PST 2024
https://github.com/rprichard updated https://github.com/llvm/llvm-project/pull/116147
>From b66919bc3356be017394cfd50bd06b776166b66a Mon Sep 17 00:00:00 2001
From: Ryan Prichard <rprichard at google.com>
Date: Wed, 13 Nov 2024 18:12:11 -0800
Subject: [PATCH 1/2] [libc++][Android] Restrict use of mblen/towctrans/wctrans
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.
---
libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp | 3 +++
libcxx/test/std/depr/depr.c.headers/wctype_h.compile.pass.cpp | 3 +++
.../test/std/language.support/support.runtime/cstdlib.pass.cpp | 3 +++
libcxx/test/std/strings/c.strings/cwctype.pass.cpp | 3 +++
4 files changed, 12 insertions(+)
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;
}
>From 137d8775753228787602120a0f292fd76a9803ed Mon Sep 17 00:00:00 2001
From: Ryan Prichard <rprichard at google.com>
Date: Wed, 13 Nov 2024 18:42:20 -0800
Subject: [PATCH 2/2] fix formatting
---
libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp | 4 ++--
.../std/language.support/support.runtime/cstdlib.pass.cpp | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
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 8199fabe3d1a68..82083734c7a263 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
@@ -142,9 +142,9 @@ int main(int, char**) {
const wchar_t* pwc = 0;
char* pc = 0;
// mblen was added in Android API 26.
-#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
+# if !defined(__ANDROID__) || __ANDROID_API__ >= 26
ASSERT_SAME_TYPE(int, decltype(mblen("",0)));
-#endif
+# 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/language.support/support.runtime/cstdlib.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
index 5f33c72f85bfbe..a00bf13936ec87 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
@@ -142,9 +142,9 @@ int main(int, char**)
const wchar_t* pwc = 0;
char* pc = 0;
// mblen was added in Android API 26.
-#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
+# if !defined(__ANDROID__) || __ANDROID_API__ >= 26
static_assert((std::is_same<decltype(std::mblen("",0)), int>::value), "");
-#endif
+# 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), "");
More information about the libcxx-commits
mailing list