aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/typeck.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-05-02 19:09:30 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-05-02 19:09:30 +0000
commitbc1aee87f6494a59eea3ffbbb0577ccd85cdc4a1 (patch)
tree026c49c2d8eadd08c56f75e225d4cb516a351820 /gcc/cp/typeck.c
parent7caed520694ee532199e889eba09a900ecce1866 (diff)
downloadgcc-bc1aee87f6494a59eea3ffbbb0577ccd85cdc4a1.zip
gcc-bc1aee87f6494a59eea3ffbbb0577ccd85cdc4a1.tar.gz
gcc-bc1aee87f6494a59eea3ffbbb0577ccd85cdc4a1.tar.bz2
PR c++/62314: C++: add fixit hint to misspelled member names
When we emit a hint about a misspelled member name, it will slightly aid readability if we use a fixit-hint to show the proposed name in context within the source code (and in the future this might support some kind of auto-apply in an IDE). This patch adds such a hint to the C++ frontend, taking us from: test.cc:10:15: error: 'struct foo' has no member named 'colour'; did you mean 'color'? return ptr->colour; ^~~~~~ to: test.cc:10:15: error: 'struct foo' has no member named 'colour'; did you mean 'color'? return ptr->colour; ^~~~~~ color gcc/cp/ChangeLog: PR c++/62314 * typeck.c (finish_class_member_access_expr): When giving a hint about a possibly-misspelled member name, add a fix-it replacement hint. gcc/testsuite/ChangeLog: PR c++/62314 * g++.dg/spellcheck-fields-2.C: New test case. From-SVN: r235785
Diffstat (limited to 'gcc/cp/typeck.c')
-rw-r--r--gcc/cp/typeck.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 7e12009..95c777d 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2817,9 +2817,21 @@ finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
tree guessed_id = lookup_member_fuzzy (access_path, name,
/*want_type=*/false);
if (guessed_id)
- error ("%q#T has no member named %qE; did you mean %qE?",
- TREE_CODE (access_path) == TREE_BINFO
- ? TREE_TYPE (access_path) : object_type, name, guessed_id);
+ {
+ location_t bogus_component_loc = input_location;
+ rich_location rich_loc (line_table, bogus_component_loc);
+ source_range bogus_component_range =
+ get_range_from_loc (line_table, bogus_component_loc);
+ rich_loc.add_fixit_replace
+ (bogus_component_range,
+ IDENTIFIER_POINTER (guessed_id));
+ error_at_rich_loc
+ (&rich_loc,
+ "%q#T has no member named %qE; did you mean %qE?",
+ TREE_CODE (access_path) == TREE_BINFO
+ ? TREE_TYPE (access_path) : object_type, name,
+ guessed_id);
+ }
else
error ("%q#T has no member named %qE",
TREE_CODE (access_path) == TREE_BINFO