Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
5.4 KiB
C++
Raw Normal View History

2010-05-11 19:42:16 +00:00
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2010-05-11 19:42:16 +00:00
//
//===----------------------------------------------------------------------===//
// <cwchar>
// XFAIL: no-wide-characters
2010-05-11 19:42:16 +00:00
#include <cwchar>
#include <ctime>
#include <cstdarg>
#include <cstdio>
2010-05-11 19:42:16 +00:00
#include <type_traits>
#include "test_macros.h"
2010-05-11 19:42:16 +00:00
#ifndef NULL
# error NULL not defined
2010-05-11 19:42:16 +00:00
#endif
#ifndef WCHAR_MAX
# error WCHAR_MAX not defined
2010-05-11 19:42:16 +00:00
#endif
#ifndef WCHAR_MIN
# error WCHAR_MIN not defined
2010-05-11 19:42:16 +00:00
#endif
#ifndef WEOF
# error WEOF not defined
2010-05-11 19:42:16 +00:00
#endif
int main(int, char**) {
std::mbstate_t mb = {};
std::size_t s = 0;
std::tm* tm = 0;
std::wint_t w = 0;
::FILE* fp = 0;
std::va_list va;
char* ns = 0;
wchar_t* ws = 0;
const wchar_t* cws = 0;
wchar_t** wsp = 0;
((void)mb); // Prevent unused warning
((void)s); // Prevent unused warning
((void)tm); // Prevent unused warning
((void)w); // Prevent unused warning
((void)fp); // Prevent unused warning
((void)va); // Prevent unused warning
((void)ns); // Prevent unused warning
((void)ws); // Prevent unused warning
((void)cws); // Prevent unused warning
((void)wsp); // Prevent unused warning
ASSERT_SAME_TYPE(int, decltype(std::fwprintf(fp, L"")));
ASSERT_SAME_TYPE(int, decltype(std::fwscanf(fp, L"")));
ASSERT_SAME_TYPE(int, decltype(std::swprintf(ws, s, L"")));
ASSERT_SAME_TYPE(int, decltype(std::swscanf(L"", L"")));
ASSERT_SAME_TYPE(int, decltype(std::vfwprintf(fp, L"", va)));
ASSERT_SAME_TYPE(int, decltype(std::vfwscanf(fp, L"", va)));
ASSERT_SAME_TYPE(int, decltype(std::vswprintf(ws, s, L"", va)));
ASSERT_SAME_TYPE(int, decltype(std::vswscanf(L"", L"", va)));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::fgetwc(fp)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::fgetws(ws, 0, fp)));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::fputwc(L' ', fp)));
ASSERT_SAME_TYPE(int, decltype(std::fputws(L"", fp)));
ASSERT_SAME_TYPE(int, decltype(std::fwide(fp, 0)));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::getwc(fp)));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::putwc(L' ', fp)));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::ungetwc(L' ', fp)));
ASSERT_SAME_TYPE(double, decltype(std::wcstod(L"", wsp)));
ASSERT_SAME_TYPE(float, decltype(std::wcstof(L"", wsp)));
ASSERT_SAME_TYPE(long double, decltype(std::wcstold(L"", wsp)));
ASSERT_SAME_TYPE(long, decltype(std::wcstol(L"", wsp, 0)));
ASSERT_SAME_TYPE(long long, decltype(std::wcstoll(L"", wsp, 0)));
ASSERT_SAME_TYPE(unsigned long, decltype(std::wcstoul(L"", wsp, 0)));
ASSERT_SAME_TYPE(unsigned long long, decltype(std::wcstoull(L"", wsp, 0)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcscpy(ws, L"")));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsncpy(ws, L"", s)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcscat(ws, L"")));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsncat(ws, L"", s)));
ASSERT_SAME_TYPE(int, decltype(std::wcscmp(L"", L"")));
ASSERT_SAME_TYPE(int, decltype(std::wcscoll(L"", L"")));
ASSERT_SAME_TYPE(int, decltype(std::wcsncmp(L"", L"", s)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsxfrm(ws, L"", s)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcschr(ws, L' ')));
ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcschr(cws, L' ')));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcscspn(L"", L"")));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcslen(L"")));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcspbrk(ws, L"")));
ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcspbrk(cws, L"")));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsrchr(ws, L' ')));
ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcsrchr(cws, L' ')));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsspn(L"", L"")));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcsstr(ws, L"")));
ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wcsstr(cws, L"")));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wcstok(ws, L"", wsp)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemchr(ws, L' ', s)));
ASSERT_SAME_TYPE(const wchar_t*, decltype(std::wmemchr(cws, L' ', s)));
ASSERT_SAME_TYPE(int, decltype(std::wmemcmp(L"", L"", s)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemcpy(ws, L"", s)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemmove(ws, L"", s)));
ASSERT_SAME_TYPE(wchar_t*, decltype(std::wmemset(ws, L' ', s)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsftime(ws, s, L"", tm)));
ASSERT_SAME_TYPE(wint_t, decltype(std::btowc(0)));
ASSERT_SAME_TYPE(int, decltype(std::wctob(w)));
ASSERT_SAME_TYPE(int, decltype(std::mbsinit(&mb)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrlen("", s, &mb)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtowc(ws, "", s, &mb)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcrtomb(ns, L' ', &mb)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbsrtowcs(ws, (const char**)0, s, &mb)));
ASSERT_SAME_TYPE(std::size_t, decltype(std::wcsrtombs(ns, (const wchar_t**)0, s, &mb)));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::getwchar()));
ASSERT_SAME_TYPE(int, decltype(std::vwscanf(L"", va)));
ASSERT_SAME_TYPE(int, decltype(std::wscanf(L"")));
ASSERT_SAME_TYPE(std::wint_t, decltype(std::putwchar(L' ')));
ASSERT_SAME_TYPE(int, decltype(std::vwprintf(L"", va)));
ASSERT_SAME_TYPE(int, decltype(std::wprintf(L"")));
Support tests in freestanding Summary: Freestanding is *weird*. The standard allows it to differ in a bunch of odd manners from regular C++, and the committee would like to improve that situation. I'd like to make libc++ behave better with what freestanding should be, so that it can be a tool we use in improving the standard. To do that we need to try stuff out, both with "freestanding the language mode" and "freestanding the library subset". Let's start with the super basic: run the libc++ tests in freestanding, using clang as the compiler, and see what works. The easiest hack to do this: In utils/libcxx/test/config.py add: self.cxx.compile_flags += ['-ffreestanding'] Run the tests and they all fail. Why? Because in freestanding `main` isn't special. This "not special" property has two effects: main doesn't get mangled, and main isn't allowed to omit its `return` statement. The first means main gets mangled and the linker can't create a valid executable for us to test. The second means we spew out warnings (ew) and the compiler doesn't insert the `return` we omitted, and main just falls of the end and does whatever undefined behavior (if you're luck, ud2 leading to non-zero return code). Let's start my work with the basics. This patch changes all libc++ tests to declare `main` as `int main(int, char**` so it mangles consistently (enabling us to declare another `extern "C"` main for freestanding which calls the mangled one), and adds `return 0;` to all places where it was missing. This touches 6124 files, and I apologize. The former was done with The Magic Of Sed. The later was done with a (not quite correct but decent) clang tool: https://gist.github.com/jfbastien/793819ff360baa845483dde81170feed This works for most tests, though I did have to adjust a few places when e.g. the test runs with `-x c`, macros are used for main (such as for the filesystem tests), etc. Once this is in we can create a freestanding bot which will prevent further regressions. After that, we can start the real work of supporting C++ freestanding fairly well in libc++. <rdar://problem/47754795> Reviewers: ldionne, mclow.lists, EricWF Subscribers: christof, jkorous, dexonsmith, arphaman, miyuki, libcxx-commits Differential Revision: https://reviews.llvm.org/D57624 llvm-svn: 353086
2019-02-04 20:31:13 +00:00
return 0;
2010-05-11 19:42:16 +00:00
}