From b66919bc3356be017394cfd50bd06b776166b66a Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Wed, 13 Nov 2024 18:12:11 -0800 Subject: [PATCH 1/3] [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 587c6b6e10ddb..8199fabe3d1a6 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 35b294532b2bd..ebbec565c1ab7 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 a1f7e1143a1e9..5f33c72f85bfb 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::value), ""); +#endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); diff --git a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp index 5bc2531d6f6ac..7460c36c357e7 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 Date: Wed, 13 Nov 2024 18:42:20 -0800 Subject: [PATCH 2/3] 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 8199fabe3d1a6..82083734c7a26 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 5f33c72f85bfb..a00bf13936ec8 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::value), ""); -#endif +# endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); From a586d0e5ad4e598c2de0f53a8e4d898385c71173 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 13 Jan 2025 17:03:23 -0800 Subject: [PATCH 3/3] Replace #if with UNSUPPORTED. We can't use XFAIL yet because the old sysroot used in the Android CI Docker image still declares these functions even for pre-API 26. The new sysroot we want to switch stop drops the declarations, unless the code is targeting API 26 or newer. --- libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp | 8 +++++--- .../std/depr/depr.c.headers/wctype_h.compile.pass.cpp | 8 +++++--- .../std/language.support/support.runtime/cstdlib.pass.cpp | 8 +++++--- libcxx/test/std/strings/c.strings/cwctype.pass.cpp | 8 +++++--- 4 files changed, 20 insertions(+), 12 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 82083734c7a26..662331558c121 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 @@ -8,6 +8,11 @@ // test +// mblen was added in Android API 26. +// TODO: Switch from UNSUPPORTED to XFAIL once the Android CI Docker sysroot is +// updated. +// UNSUPPORTED: LIBCXX-ANDROID-FIXME && target={{.+}}-android{{(eabi)?(21|22|23|24|25)}} + #include #include #include @@ -141,10 +146,7 @@ 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 ebbec565c1ab7..4e2fb319336f1 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 @@ -8,6 +8,11 @@ // UNSUPPORTED: no-wide-characters +// towctrans and wctrans were added in Android API 26. +// TODO: Switch from UNSUPPORTED to XFAIL once the Android CI Docker sysroot is +// updated. +// UNSUPPORTED: LIBCXX-ANDROID-FIXME && target={{.+}}-android{{(eabi)?(21|22|23|24|25)}} + // #include @@ -109,8 +114,5 @@ 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 a00bf13936ec8..9d3e6d892daf0 100644 --- a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp +++ b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp @@ -8,6 +8,11 @@ // test +// mblen was added in Android API 26. +// TODO: Switch from UNSUPPORTED to XFAIL once the Android CI Docker sysroot is +// updated. +// UNSUPPORTED: LIBCXX-ANDROID-FIXME && target={{.+}}-android{{(eabi)?(21|22|23|24|25)}} + #include #include #include @@ -141,10 +146,7 @@ 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::value), ""); -# endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); diff --git a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp index 7460c36c357e7..0deabf51ed59c 100644 --- a/libcxx/test/std/strings/c.strings/cwctype.pass.cpp +++ b/libcxx/test/std/strings/c.strings/cwctype.pass.cpp @@ -10,6 +10,11 @@ // UNSUPPORTED: no-wide-characters +// towctrans and wctrans were added in Android API 26. +// TODO: Switch from UNSUPPORTED to XFAIL once the Android CI Docker sysroot is +// updated. +// UNSUPPORTED: LIBCXX-ANDROID-FIXME && target={{.+}}-android{{(eabi)?(21|22|23|24|25)}} + #include #include @@ -111,11 +116,8 @@ 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; }