aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-15 23:57:01 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-15 23:57:01 +0000
commitd9020fe61291812489bd4bb954c0c04ac088ac6f (patch)
tree802052306a708cf70c39ab01f29991c7f405d639 /libcpp
parentb74250bce94c2415c150a9fb6c43b853d754bfa2 (diff)
fix-it hints can't contain newlines
I hope to implement newline support within fix-it hints at some point, but currently it's not supported, and leads to misleading diagnostic output, so for now, fail gracefully. gcc/ChangeLog: * diagnostic-show-locus.c (selftest::test_fixit_insert_containing_newline): New function. (selftest::test_fixit_replace_containing_newline): New function. (selftest::diagnostic_show_locus_c_tests): Call the above. libcpp/ChangeLog: * include/line-map.h (class rich_location): Note that newlines aren't supported in fix-it text. * line-map.c (rich_location::add_fixit_insert_before): Reject attempts to add fix-its containing newlines. (rich_location::add_fixit_replace): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240169 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog8
-rw-r--r--libcpp/include/line-map.h2
-rw-r--r--libcpp/line-map.c13
3 files changed, 23 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 95e12a9ba6b..b2b36037463 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,11 @@
+2016-09-15 David Malcolm <dmalcolm@redhat.com>
+
+ * include/line-map.h (class rich_location): Note that newlines
+ aren't supported in fix-it text.
+ * line-map.c (rich_location::add_fixit_insert_before): Reject
+ attempts to add fix-its containing newlines.
+ (rich_location::add_fixit_replace): Likewise.
+
2016-09-13 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h (class rich_location): Add description of
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 939bfcc5712..747609d4393 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1551,6 +1551,8 @@ class fixit_hint;
Attempts to add a fix-it hint within a macro expansion will fail.
+ We do not yet support newlines in fix-it text; attempts to do so will fail.
+
The rich_location API handles these failures gracefully, so that
diagnostics can attempt to add fix-it hints without each needing
extensive checking.
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 742af0a07bb..07e3acb78a5 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -2128,6 +2128,12 @@ rich_location::add_fixit_insert_before (source_location where,
if (reject_impossible_fixit (start))
return;
+ /* We do not yet support newlines within fix-it hints. */
+ if (strchr (new_content, '\n'))
+ {
+ stop_supporting_fixits ();
+ return;
+ }
add_fixit (new fixit_insert (start, new_content));
}
@@ -2271,6 +2277,13 @@ rich_location::add_fixit_replace (source_range src_range,
if (reject_impossible_fixit (src_range.m_finish))
return;
+ /* We do not yet support newlines within fix-it hints. */
+ if (strchr (new_content, '\n'))
+ {
+ stop_supporting_fixits ();
+ return;
+ }
+
/* Consolidate neighboring fixits. */
fixit_hint *prev = get_last_fixit_hint ();
if (prev)