2014-01-16 10:37:08 +08:00
|
|
|
// RUN: %clang_cc1 %s -fsyntax-only -verify
|
2017-10-07 07:09:55 +08:00
|
|
|
// RUN: %clang_cc1 %s -fsyntax-only -fwchar-type=short -fno-signed-wchar -verify -DSHORT_WCHAR
|
2009-11-17 22:02:16 +08:00
|
|
|
|
|
|
|
typedef __WCHAR_TYPE__ wchar_t;
|
|
|
|
|
2009-11-06 04:14:16 +08:00
|
|
|
#if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \
|
2016-05-17 01:22:25 +08:00
|
|
|
|| defined(_M_X64) || defined(__ORBIS__) || defined(SHORT_WCHAR)
|
2009-11-06 04:14:16 +08:00
|
|
|
#define WCHAR_T_TYPE unsigned short
|
2013-02-07 23:11:44 +08:00
|
|
|
#elif defined(__arm) || defined(__aarch64__)
|
2012-09-25 18:11:17 +08:00
|
|
|
#define WCHAR_T_TYPE unsigned int
|
2014-08-14 23:14:51 +08:00
|
|
|
#elif defined(__sun)
|
Clang :: Sema/wchar.c has long been failing on Solaris:
error: 'error' diagnostics expected but not seen:
File /vol/llvm/src/clang/local/test/Sema/wchar.c Line 22: initializing wide char array with non-wide string literal
error: 'error' diagnostics seen but not expected:
File /vol/llvm/src/clang/local/test/Sema/wchar.c Line 20: array initializer must be an initializer list
File /vol/llvm/src/clang/local/test/Sema/wchar.c Line 22: array initializer must be an initializer list
It turns out the definition is wrong, as can be seen in GCC's gcc/config/sol2.h:
/* wchar_t is called differently in <wchar.h> for 32 and 64-bit
compilations. This is called for by SCD 2.4.1, p. 6-83, Figure 6-65
(32-bit) and p. 6P-10, Figure 6.38 (64-bit). */
#undef WCHAR_TYPE
#define WCHAR_TYPE (TARGET_64BIT ? "int" : "long int")
The following patch implements this, and at the same time corrects the wint_t
definition which is the same:
/* Same for wint_t. See SCD 2.4.1, p. 6-83, Figure 6-66 (32-bit). There's
no corresponding 64-bit definition, but this is what Solaris 8
<iso/wchar_iso.h> uses. */
#undef WINT_TYPE
#define WINT_TYPE (TARGET_64BIT ? "int" : "long int")
Clang :: Preprocessor/wchar_t.c and Clang :: Sema/format-strings.c need to
be adjusted to account for that.
Tested on i386-pc-solaris2.11, x86_64-pc-solaris2.11, and x86_64-pc-linux-gnu.
Differential Revision: https://reviews.llvm.org/D62944
llvm-svn: 363612
2019-06-18 04:21:25 +08:00
|
|
|
#if defined(__LP64__)
|
|
|
|
#define WCHAR_T_TYPE int
|
|
|
|
#else
|
|
|
|
#define WCHAR_T_TYPE long
|
|
|
|
#endif
|
2014-08-14 23:14:51 +08:00
|
|
|
#else /* Solaris. */
|
2009-11-06 04:14:16 +08:00
|
|
|
#define WCHAR_T_TYPE int
|
|
|
|
#endif
|
|
|
|
|
2009-02-27 07:36:02 +08:00
|
|
|
int check_wchar_size[sizeof(*L"") == sizeof(wchar_t) ? 1 : -1];
|
2009-11-06 04:14:16 +08:00
|
|
|
|
2009-02-27 07:36:02 +08:00
|
|
|
void foo() {
|
2009-11-06 04:14:16 +08:00
|
|
|
WCHAR_T_TYPE t1[] = L"x";
|
2009-02-27 07:36:02 +08:00
|
|
|
wchar_t tab[] = L"x";
|
2013-05-15 19:03:04 +08:00
|
|
|
WCHAR_T_TYPE t2[] = "x"; // expected-error {{initializing wide char array with non-wide string literal}}
|
|
|
|
char t3[] = L"x"; // expected-error {{initializing char array with wide string literal}}
|
2009-02-27 07:36:02 +08:00
|
|
|
}
|