aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-12-06 20:02:55 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-12-06 20:02:55 +0000
commitc79144f8353af3292903c9c8e508f1de986eb6b0 (patch)
tree7cd052f971408e0cf364391b328c2c1c9d64b38d /gcc/c
parent613bc14fcd3f6b58289aca9a2980cacfc2e75299 (diff)
downloadgcc-c79144f8353af3292903c9c8e508f1de986eb6b0.zip
gcc-c79144f8353af3292903c9c8e508f1de986eb6b0.tar.gz
gcc-c79144f8353af3292903c9c8e508f1de986eb6b0.tar.bz2
C/C++: don't suggest implementation names as spelling fixes (PR c/83236)
gcc/c-family/ChangeLog: PR c/83236 * c-common.c (selftest::c_family_tests): Call selftest::c_spellcheck_cc_tests. * c-common.h (selftest::c_spellcheck_cc_tests): New decl. * c-spellcheck.cc: Include "selftest.h". (name_reserved_for_implementation_p): New function. (should_suggest_as_macro_p): New function. (find_closest_macro_cpp_cb): Move the check for NT_MACRO to should_suggest_as_macro_p and call it. (selftest::test_name_reserved_for_implementation_p): New function. (selftest::c_spellcheck_cc_tests): New function. * c-spellcheck.h (name_reserved_for_implementation_p): New decl. gcc/c/ChangeLog: PR c/83236 * c-decl.c (lookup_name_fuzzy): Don't suggest names that are reserved for use by the implementation. gcc/cp/ChangeLog: PR c/83236 * name-lookup.c (consider_binding_level): Don't suggest names that are reserved for use by the implementation. gcc/testsuite/ChangeLog: PR c/83236 * c-c++-common/spellcheck-reserved.c: New test case. From-SVN: r255453
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c12
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index b89939e..91267c0 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,5 +1,11 @@
2017-12-06 David Malcolm <dmalcolm@redhat.com>
+ PR c/83236
+ * c-decl.c (lookup_name_fuzzy): Don't suggest names that are
+ reserved for use by the implementation.
+
+2017-12-06 David Malcolm <dmalcolm@redhat.com>
+
* c-decl.c: Include "c-family/c-spellcheck.h".
2017-12-05 Martin Liska <mliska@suse.cz>
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index d7dad1a..607c705 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -4027,6 +4027,10 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
IDENTIFIER_POINTER (name),
header_hint));
+ /* Only suggest names reserved for the implementation if NAME begins
+ with an underscore. */
+ bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
+
best_match<tree, tree> bm (name);
/* Look within currently valid scopes. */
@@ -4042,6 +4046,14 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
if (TREE_CODE (binding->decl) == FUNCTION_DECL)
if (C_DECL_IMPLICIT (binding->decl))
continue;
+ /* Don't suggest names that are reserved for use by the
+ implementation, unless NAME began with an underscore. */
+ if (!consider_implementation_names)
+ {
+ const char *suggestion_str = IDENTIFIER_POINTER (binding->id);
+ if (name_reserved_for_implementation_p (suggestion_str))
+ continue;
+ }
switch (kind)
{
case FUZZY_LOOKUP_TYPENAME: