[libc++] Add an option to disable wide character support in libc++

Some embedded platforms do not wish to support the C library functionality
for handling wchar_t because they have no use for it. It makes sense for
libc++ to work properly on those platforms, so this commit adds a carve-out
of functionality for wchar_t.

Unfortunately, unlike some other carve-outs (e.g. random device), this
patch touches several parts of the library. However, despite the wide
impact of this patch, I still think it is important to support this
configuration since it makes it much simpler to port libc++ to some
embedded platforms.

Differential Revision: https://reviews.llvm.org/D111265
This commit is contained in:
Louis Dionne
2021-08-23 15:32:36 -04:00
parent c6828e0cea
commit f4c1258d56
612 changed files with 3833 additions and 1633 deletions

View File

@@ -68,6 +68,7 @@ int main(int, char**)
assert(sb.sputc('1') == '1');
assert(sb.str() == "12345678901");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
testbuf<wchar_t> sb(L"abc");
assert(sb.sputc(L'1') == L'1');
@@ -93,6 +94,7 @@ int main(int, char**)
assert(sb.sputc(L'1') == L'1');
assert(sb.str() == L"12345678901");
}
#endif
{
testbuf<char> sb("abc", std::ios_base::app | std::ios_base::out);
assert(sb.sputc('1') == '1');

View File

@@ -68,6 +68,7 @@ int main(int, char**)
assert(sb.pbackfail(std::char_traits<char>::eof()) == std::char_traits<char>::eof());
assert(sb.str() == "133");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
testbuf<wchar_t> sb(L"123", std::ios_base::in);
assert(sb.sgetc() == L'1');
@@ -95,6 +96,7 @@ int main(int, char**)
assert(sb.pbackfail(std::char_traits<wchar_t>::eof()) == std::char_traits<wchar_t>::eof());
assert(sb.str() == L"133");
}
#endif
return 0;
}

View File

@@ -105,6 +105,7 @@ int main(int, char**)
assert(sb.sputc('c') == 'c');
assert(sb.str() == "0123456c89");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::wstringbuf sb(L"0123456789", std::ios_base::in);
assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
@@ -165,6 +166,7 @@ int main(int, char**)
assert(sb.sputc(L'c') == L'c');
assert(sb.str() == L"0123456c89");
}
#endif // TEST_HAS_NO_WIDE_CHARACTERS
return 0;
}

View File

@@ -48,6 +48,7 @@ int main(int, char**)
assert(sb.sputc('3') == '3');
assert(sb.str() == "0123456789");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::wstringbuf sb(L"0123456789", std::ios_base::in);
assert(sb.pubseekpos(3, std::ios_base::out) == -1);
@@ -75,6 +76,7 @@ int main(int, char**)
assert(sb.sputc(L'3') == L'3');
assert(sb.str() == L"0123456789");
}
#endif
return 0;
}

View File

@@ -25,11 +25,13 @@ int main(int, char**)
assert(sb.pubsetbuf(0, 0) == &sb);
assert(sb.str() == "0123456789");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::wstringbuf sb(L"0123456789");
assert(sb.pubsetbuf(0, 0) == &sb);
assert(sb.str() == L"0123456789");
}
#endif
return 0;
}

View File

@@ -50,6 +50,7 @@ int main(int, char**)
assert(sb.underflow() == '4');
assert(sb.underflow() == '4');
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
testbuf<wchar_t> sb(L"123");
sb.pbump(3);
@@ -68,6 +69,7 @@ int main(int, char**)
assert(sb.underflow() == L'4');
assert(sb.underflow() == L'4');
}
#endif // TEST_HAS_NO_WIDE_CHARACTERS
return 0;
}