aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndreas Krebbel <krebbel@linux.ibm.com>2018-06-25 07:16:59 +0000
committerAndreas Krebbel <krebbel@gcc.gnu.org>2018-06-25 07:16:59 +0000
commit4f1c88ae5892fad3d0cf248c6da5ffb51a61c9aa (patch)
treea711fc4960082a402a1883a26bd05cb740675df1 /gcc
parentc5ce6638f4deb1417bed3666077822cc5fb12dc9 (diff)
downloadgcc-4f1c88ae5892fad3d0cf248c6da5ffb51a61c9aa.zip
gcc-4f1c88ae5892fad3d0cf248c6da5ffb51a61c9aa.tar.gz
gcc-4f1c88ae5892fad3d0cf248c6da5ffb51a61c9aa.tar.bz2
C++: Fix PR86082
When turning a user-defined numerical literal into an operator invocation the literal needs to be translated to the execution character set. gcc/cp/ChangeLog: 2018-06-25 Andreas Krebbel <krebbel@linux.ibm.com> PR C++/86082 * parser.c (make_char_string_pack): Pass this literal chars through cpp_interpret_string. (cp_parser_userdef_numeric_literal): Check the result of make_char_string_pack. gcc/testsuite/ChangeLog: 2018-06-25 Andreas Krebbel <krebbel@linux.ibm.com> PR C++/86082 * g++.dg/pr86082.C: New test. From-SVN: r262003
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/cp/parser.c17
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/pr86082.C18
4 files changed, 47 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c40df21..f612c5b5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2018-06-25 Andreas Krebbel <krebbel@linux.ibm.com>
+
+ PR C++/86082
+ * parser.c (make_char_string_pack): Pass this literal chars
+ through cpp_interpret_string.
+ (cp_parser_userdef_numeric_literal): Check the result of
+ make_char_string_pack.
+
2018-06-24 Maya Rashish <coypu@sdf.org>
* ginclude/stddef.h: Simplify conditions around avoiding
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 154729c..5e1b67c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4291,7 +4291,16 @@ make_char_string_pack (tree value)
/* 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 (char_type_node, str[i]);
+ {
+ unsigned char s[3] = { '\'', str[i], '\'' };
+ cpp_string in = { 3, s };
+ cpp_string out = { 0, 0 };
+ if (!cpp_interpret_string (parse_in, &in, 1, &out, CPP_STRING))
+ return NULL_TREE;
+ gcc_assert (out.len == 2);
+ TREE_VEC_ELT (charvec, i) = build_int_cst (char_type_node,
+ out.text[0]);
+ }
/* Build the argument packs. */
SET_ARGUMENT_PACK_ARGS (argpack, charvec);
@@ -4407,6 +4416,12 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
if (decl && decl != error_mark_node)
{
tree tmpl_args = make_char_string_pack (num_string);
+ if (tmpl_args == NULL_TREE)
+ {
+ error ("failed to translate literal to execution character set %qT",
+ num_string);
+ return error_mark_node;
+ }
decl = lookup_template_function (decl, tmpl_args);
result = finish_call_expr (decl, &args, false, true,
tf_warning_or_error);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5ff08f0..4ca7d21 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-06-25 Andreas Krebbel <krebbel@linux.ibm.com>
+
+ PR C++/86082
+ * g++.dg/pr86082.C: New test.
+
2018-06-24 Tom de Vries <tdevries@suse.de>
* g++.dg/guality/guality.exp: Don't use which on gdb arg to report_gdb.
diff --git a/gcc/testsuite/g++.dg/pr86082.C b/gcc/testsuite/g++.dg/pr86082.C
new file mode 100644
index 0000000..c7247cd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr86082.C
@@ -0,0 +1,18 @@
+/* { dg-do link } */
+/* { dg-options "-fexec-charset=IBM1047 -std=c++11" } */
+
+/* When turning 123_test into an operator invocation the literal 123
+ needs to be translated to the execution character set. Failing to
+ do so results in a link error since '1', '2', and '3' in the
+ specialization will be translated as string literals. */
+
+template <char... p> void q();
+template <> void q<'1','2','3'>() {}
+
+template <char... p> void operator""_test() { q<p...> (); }
+
+int
+main ()
+{
+ 123_test;
+}