summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-06-20 16:37:28 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-06-20 16:37:28 +0000
commitecbea05a82f27e54e4cc17a60a456fed58c51631 (patch)
tree5df2315bb993f48933d4efe20cb3866896e28adf
parent8f097cf7a19a76e56246ed465c0169a4f91de8bc (diff)
downloadgcc-ecbea05a82f27e54e4cc17a60a456fed58c51631.tar.gz
C++ FE: Show both locations in string literal concatenation error
gcc/cp/ChangeLog: * parser.c (cp_parser_string_literal): Convert non-standard concatenation error to directly use a rich_location, and use that to add the location of the first literal to the diagnostic. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/string-literal-concat.C: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237608 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.c15
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C23
4 files changed, 44 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8ff9630e866..6508b6ed03e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2016-06-20 David Malcolm <dmalcolm@redhat.com>
+
+ * parser.c (cp_parser_string_literal): Convert non-standard
+ concatenation error to directly use a rich_location, and
+ use that to add the location of the first literal to the
+ diagnostic.
+
2016-06-17 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (validate_constexpr_redeclaration): Change pair of errors
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0846f0c04ea..d1f06fdb861 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3893,13 +3893,12 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok,
}
else
{
- location_t last_tok_loc;
+ location_t last_tok_loc = tok->location;
gcc_obstack_init (&str_ob);
count = 0;
do
{
- last_tok_loc = tok->location;
cp_lexer_consume_token (parser->lexer);
count++;
str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
@@ -3931,13 +3930,19 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok,
if (type == CPP_STRING)
type = curr_type;
else if (curr_type != CPP_STRING)
- error_at (tok->location,
- "unsupported non-standard concatenation "
- "of string literals");
+ {
+ rich_location rich_loc (line_table, tok->location);
+ rich_loc.add_range (last_tok_loc, false);
+ error_at_rich_loc (&rich_loc,
+ "unsupported non-standard concatenation "
+ "of string literals");
+ }
}
obstack_grow (&str_ob, &str, sizeof (cpp_string));
+ last_tok_loc = tok->location;
+
tok = cp_lexer_peek_token (parser->lexer);
if (cpp_userdef_string_p (tok->type))
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0570b224f21..1d438528a07 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-06-20 David Malcolm <dmalcolm@redhat.com>
+
+ * g++.dg/diagnostic/string-literal-concat.C: New test case.
+
2016-06-20 Martin Sebor <msebor@redhat.com>
PR c/69507
diff --git a/gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C b/gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C
new file mode 100644
index 00000000000..4ede799da8d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C
@@ -0,0 +1,23 @@
+/* { dg-options "-fdiagnostics-show-caret -std=c++11" } */
+
+const void *s = u8"a" u"b"; // { dg-error "24: non-standard concatenation" }
+/* { dg-begin-multiline-output "" }
+ const void *s = u8"a" u"b";
+ ~~~~~ ^~~~
+ { dg-end-multiline-output "" } */
+
+const void *s2 = u"a" u"b" u8"c"; // { dg-error "30: non-standard concatenation" }
+/* { dg-begin-multiline-output "" }
+ const void *s2 = u"a" u"b" u8"c";
+ ~~~~ ^~~~~
+ { dg-end-multiline-output "" } */
+
+#define TEST_U8_LITERAL u8"a"
+
+const void *s3 = TEST_U8_LITERAL u8"b";
+
+const void *s4 = TEST_U8_LITERAL u"b"; // { dg-error "34: non-standard concatenation" }
+/* { dg-begin-multiline-output "" }
+ const void *s4 = TEST_U8_LITERAL u"b";
+ ^~~~
+ { dg-end-multiline-output "" } */