===================================================================
@@ -3793,22 +3793,39 @@
tree charvec;
tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
const char *str = TREE_STRING_POINTER (value);
- int i, len = TREE_STRING_LENGTH (value) - 1;
+ int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value))));
+ int len = TREE_STRING_LENGTH (value) / sz - 1;
tree argvec = make_tree_vec (2);
- tree string_char_type_node = TREE_TYPE (TREE_TYPE (value));
+ tree str_char_type_node = TREE_TYPE (TREE_TYPE (value));
+ str_char_type_node = TYPE_MAIN_VARIANT (str_char_type_node);
/* First template parm is character type. */
- TREE_VEC_ELT (argvec, 0) = string_char_type_node;
+ TREE_VEC_ELT (argvec, 0) = str_char_type_node;
/* Fill in CHARVEC with all of the parameters. */
charvec = make_tree_vec (len);
- for (i = 0; i < len; ++i)
- TREE_VEC_ELT (charvec, i) = build_int_cst (string_char_type_node, str[i]);
+ if (sz == 1)
+ {
+ for (int i = 0; i < len; ++i)
+ TREE_VEC_ELT (charvec, i) = build_int_cst (str_char_type_node, str[i]);
+ }
+ else if (sz == 2)
+ {
+ const uint16_t *num = (const uint16_t *)str;
+ for (int i = 0; i < len; ++i)
+ TREE_VEC_ELT (charvec, i) = build_int_cst (str_char_type_node, num[i]);
+ }
+ else if (sz == 4)
+ {
+ const uint32_t *num = (const uint32_t *)str;
+ for (int i = 0; i < len; ++i)
+ TREE_VEC_ELT (charvec, i) = build_int_cst (str_char_type_node, num[i]);
+ }
/* Build the argument packs. */
SET_ARGUMENT_PACK_ARGS (argpack, charvec);
- TREE_TYPE (argpack) = string_char_type_node;
+ TREE_TYPE (argpack) = str_char_type_node;
TREE_VEC_ELT (argvec, 1) = argpack;
===================================================================
@@ -0,0 +1,68 @@
+// { dg-options -std=c++1y }
+// { dg-do run }
+
+#include <type_traits>
+
+struct Foo
+{
+ bool type[4];
+ bool const_type[4];
+ int chars[10];
+};
+
+template<typename CharT, CharT... str>
+Foo
+operator""_foo()
+{
+ CharT arr[]{str...};
+
+ Foo foo;
+
+ foo.type[0] = std::is_same<CharT, char>::value;
+ foo.type[1] = std::is_same<CharT, wchar_t>::value;
+ foo.type[2] = std::is_same<CharT, char16_t>::value;
+ foo.type[3] = std::is_same<CharT, char32_t>::value;
+ foo.const_type[0] = std::is_same<CharT, const char>::value;
+ foo.const_type[1] = std::is_same<CharT, const wchar_t>::value;
+ foo.const_type[2] = std::is_same<CharT, const char16_t>::value;
+ foo.const_type[3] = std::is_same<CharT, const char32_t>::value;
+
+ for(int i; i < sizeof(arr)/sizeof(CharT) - 1; ++i)
+ foo.chars[i] = (int)arr[i];
+
+ return foo;
+}
+
+int
+main()
+{
+ Foo foo;
+
+ foo = U"\x10000\x10001\x10002"_foo;
+ if (foo.type[3] != true) __builtin_abort();
+ if (sizeof(foo.chars)/sizeof(char32_t)-1 != 3) __builtin_abort();
+ if (foo.chars[0] != 65536) __builtin_abort();
+ if (foo.chars[1] != 65537) __builtin_abort();
+ if (foo.chars[2] != 65538) __builtin_abort();
+
+ foo = "\x61\x62\x63"_foo;
+ if (foo.type[0] != true) __builtin_abort();
+ if (sizeof(foo.chars)/sizeof(char)-1 != 3) __builtin_abort();
+ if (foo.chars[0] != 97) __builtin_abort();
+ if (foo.chars[1] != 98) __builtin_abort();
+ if (foo.chars[2] != 99) __builtin_abort();
+
+ foo = L"\x01020304\x05060708"_foo;
+ if (foo.type[1] != true) __builtin_abort();
+ if (sizeof(foo.chars)/sizeof(wchar_t)-1 != 2) __builtin_abort();
+ if (foo.chars[0] != 16909060) __builtin_abort();
+ if (foo.chars[1] != 84281096) __builtin_abort();
+
+ foo = u"\x0102\x0304\x0506\x0708"_foo;
+ if (foo.type[2] != true) __builtin_abort();
+ if (sizeof(foo.chars)/sizeof(char16_t)-1 != 4) __builtin_abort();
+ if (foo.chars[0] != 258) __builtin_abort();
+ if (foo.chars[1] != 772) __builtin_abort();
+ if (foo.chars[2] != 1286) __builtin_abort();
+ if (foo.chars[3] != 1800) __builtin_abort();
+}