string-init.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // RUN: %clang_cc1 -std=c11 -fsyntax-only -triple x86_64-pc-linux -verify %s
  2. // Note: these match the types specified by the target above.
  3. typedef int wchar_t;
  4. typedef unsigned short char16_t;
  5. typedef unsigned int char32_t;
  6. void f() {
  7. char a1[] = "a"; // No error.
  8. char a2[] = u8"a"; // No error.
  9. char a3[] = u"a"; // expected-error{{initializing char array with wide string literal}}
  10. char a4[] = U"a"; // expected-error{{initializing char array with wide string literal}}
  11. char a5[] = L"a"; // expected-error{{initializing char array with wide string literal}}
  12. wchar_t b1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}}
  13. wchar_t b2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}}
  14. wchar_t b3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  15. wchar_t b4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  16. wchar_t b5[] = L"a"; // No error.
  17. char16_t c1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}}
  18. char16_t c2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}}
  19. char16_t c3[] = u"a"; // No error.
  20. char16_t c4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  21. char16_t c5[] = L"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  22. char32_t d1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}}
  23. char32_t d2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}}
  24. char32_t d3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  25. char32_t d4[] = U"a"; // No error.
  26. char32_t d5[] = L"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  27. int e1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}}
  28. int e2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}}
  29. int e3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  30. int e4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}}
  31. int e5[] = L"a"; // No error.
  32. long f1[] = "a"; // expected-error{{array initializer must be an initializer list}}
  33. long f2[] = u8"a"; // expected-error{{array initializer must be an initializer list}}}
  34. long f3[] = u"a"; // expected-error{{array initializer must be an initializer list}}
  35. long f4[] = U"a"; // expected-error{{array initializer must be an initializer list}}
  36. long f5[] = L"a"; // expected-error{{array initializer must be an initializer list}}
  37. }
  38. void g() {
  39. char a[] = 1; // expected-error{{array initializer must be an initializer list or string literal}}
  40. wchar_t b[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}}
  41. char16_t c[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}}
  42. char32_t d[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}}
  43. }