1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <cwchar> 11 12 #include <cwchar> 13 #include <cstdarg> 14 #include <type_traits> 15 16 #ifndef NULL 17 #error NULL not defined 18 #endif 19 20 #ifndef WCHAR_MAX 21 #error WCHAR_MAX not defined 22 #endif 23 24 #ifndef WCHAR_MIN 25 #error WCHAR_MIN not defined 26 #endif 27 28 #ifndef WEOF 29 #error WEOF not defined 30 #endif 31 32 int main() 33 { 34 std::mbstate_t mb = {}; 35 std::size_t s = 0; 36 std::tm *tm = 0; 37 std::wint_t w = 0; 38 ::FILE* fp = 0; 39 std::va_list va; 40 41 char* ns = 0; 42 wchar_t* ws = 0; 43 44 ((void)mb); // Prevent unused warning 45 ((void)s); // Prevent unused warning 46 ((void)tm); // Prevent unused warning 47 ((void)w); // Prevent unused warning 48 ((void)fp); // Prevent unused warning 49 ((void)va); // Prevent unused warning 50 ((void)ns); // Prevent unused warning 51 ((void)ws); // Prevent unused warning 52 53 static_assert((std::is_same<decltype(std::fwprintf(fp, L"")), int>::value), ""); 54 static_assert((std::is_same<decltype(std::fwscanf(fp, L"")), int>::value), ""); 55 static_assert((std::is_same<decltype(std::swprintf(ws, s, L"")), int>::value), ""); 56 static_assert((std::is_same<decltype(std::swscanf(L"", L"")), int>::value), ""); 57 static_assert((std::is_same<decltype(std::vfwprintf(fp, L"", va)), int>::value), ""); 58 static_assert((std::is_same<decltype(std::vfwscanf(fp, L"", va)), int>::value), ""); 59 static_assert((std::is_same<decltype(std::vswprintf(ws, s, L"", va)), int>::value), ""); 60 static_assert((std::is_same<decltype(std::vswscanf(L"", L"", va)), int>::value), ""); 61 static_assert((std::is_same<decltype(std::fgetwc(fp)), std::wint_t>::value), ""); 62 static_assert((std::is_same<decltype(std::fgetws(ws, 0, fp)), wchar_t*>::value), ""); 63 static_assert((std::is_same<decltype(std::fputwc(L' ', fp)), std::wint_t>::value), ""); 64 static_assert((std::is_same<decltype(std::fputws(L"", fp)), int>::value), ""); 65 static_assert((std::is_same<decltype(std::fwide(fp, 0)), int>::value), ""); 66 static_assert((std::is_same<decltype(std::getwc(fp)), std::wint_t>::value), ""); 67 static_assert((std::is_same<decltype(std::putwc(L' ', fp)), std::wint_t>::value), ""); 68 static_assert((std::is_same<decltype(std::ungetwc(L' ', fp)), std::wint_t>::value), ""); 69 static_assert((std::is_same<decltype(std::wcstod(L"", (wchar_t**)0)), double>::value), ""); 70 static_assert((std::is_same<decltype(std::wcstof(L"", (wchar_t**)0)), float>::value), ""); 71 static_assert((std::is_same<decltype(std::wcstold(L"", (wchar_t**)0)), long double>::value), ""); 72 static_assert((std::is_same<decltype(std::wcstol(L"", (wchar_t**)0, 0)), long>::value), ""); 73 static_assert((std::is_same<decltype(std::wcstoll(L"", (wchar_t**)0, 0)), long long>::value), ""); 74 static_assert((std::is_same<decltype(std::wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), ""); 75 static_assert((std::is_same<decltype(std::wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), ""); 76 static_assert((std::is_same<decltype(std::wcscpy(ws, L"")), wchar_t*>::value), ""); 77 static_assert((std::is_same<decltype(std::wcsncpy(ws, L"", s)), wchar_t*>::value), ""); 78 static_assert((std::is_same<decltype(std::wcscat(ws, L"")), wchar_t*>::value), ""); 79 static_assert((std::is_same<decltype(std::wcsncat(ws, L"", s)), wchar_t*>::value), ""); 80 static_assert((std::is_same<decltype(std::wcscmp(L"", L"")), int>::value), ""); 81 static_assert((std::is_same<decltype(std::wcscoll(L"", L"")), int>::value), ""); 82 static_assert((std::is_same<decltype(std::wcsncmp(L"", L"", s)), int>::value), ""); 83 static_assert((std::is_same<decltype(std::wcsxfrm(ws, L"", s)), std::size_t>::value), ""); 84 static_assert((std::is_same<decltype(std::wcschr((wchar_t*)0, L' ')), wchar_t*>::value), ""); 85 static_assert((std::is_same<decltype(std::wcscspn(L"", L"")), std::size_t>::value), ""); 86 static_assert((std::is_same<decltype(std::wcslen(L"")), std::size_t>::value), ""); 87 static_assert((std::is_same<decltype(std::wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), ""); 88 static_assert((std::is_same<decltype(std::wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), ""); 89 static_assert((std::is_same<decltype(std::wcsspn(L"", L"")), std::size_t>::value), ""); 90 static_assert((std::is_same<decltype(std::wcsstr((wchar_t*)0, L"")), wchar_t*>::value), ""); 91 static_assert((std::is_same<decltype(std::wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), ""); 92 static_assert((std::is_same<decltype(std::wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), ""); 93 static_assert((std::is_same<decltype(std::wmemcmp(L"", L"", s)), int>::value), ""); 94 static_assert((std::is_same<decltype(std::wmemcpy(ws, L"", s)), wchar_t*>::value), ""); 95 static_assert((std::is_same<decltype(std::wmemmove(ws, L"", s)), wchar_t*>::value), ""); 96 static_assert((std::is_same<decltype(std::wmemset(ws, L' ', s)), wchar_t*>::value), ""); 97 static_assert((std::is_same<decltype(std::wcsftime(ws, s, L"", tm)), std::size_t>::value), ""); 98 static_assert((std::is_same<decltype(std::btowc(0)), wint_t>::value), ""); 99 static_assert((std::is_same<decltype(std::wctob(w)), int>::value), ""); 100 static_assert((std::is_same<decltype(std::mbsinit(&mb)), int>::value), ""); 101 static_assert((std::is_same<decltype(std::mbrlen("", s, &mb)), std::size_t>::value), ""); 102 static_assert((std::is_same<decltype(std::mbrtowc(ws, "", s, &mb)), std::size_t>::value), ""); 103 static_assert((std::is_same<decltype(std::wcrtomb(ns, L' ', &mb)), std::size_t>::value), ""); 104 static_assert((std::is_same<decltype(std::mbsrtowcs(ws, (const char**)0, s, &mb)), std::size_t>::value), ""); 105 static_assert((std::is_same<decltype(std::wcsrtombs(ns, (const wchar_t**)0, s, &mb)), std::size_t>::value), ""); 106 107 // These tests fail on systems whose C library doesn't provide a correct overload 108 // set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr, unless the compiler is 109 // a suitably recent version of Clang. 110 #if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD) 111 static_assert((std::is_same<decltype(std::wcschr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); 112 static_assert((std::is_same<decltype(std::wcspbrk((const wchar_t*)0, L"")), const wchar_t*>::value), ""); 113 static_assert((std::is_same<decltype(std::wcsrchr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); 114 static_assert((std::is_same<decltype(std::wcsstr((const wchar_t*)0, L"")), const wchar_t*>::value), ""); 115 static_assert((std::is_same<decltype(std::wmemchr((const wchar_t*)0, L' ', s)), const wchar_t*>::value), ""); 116 #endif 117 118 #ifndef _LIBCPP_HAS_NO_STDIN 119 static_assert((std::is_same<decltype(std::getwchar()), std::wint_t>::value), ""); 120 static_assert((std::is_same<decltype(std::vwscanf(L"", va)), int>::value), ""); 121 static_assert((std::is_same<decltype(std::wscanf(L"")), int>::value), ""); 122 #endif 123 124 #ifndef _LIBCPP_HAS_NO_STDOUT 125 static_assert((std::is_same<decltype(std::putwchar(L' ')), std::wint_t>::value), ""); 126 static_assert((std::is_same<decltype(std::vwprintf(L"", va)), int>::value), ""); 127 static_assert((std::is_same<decltype(std::wprintf(L"")), int>::value), ""); 128 #endif 129 } 130