From dd36b8775fb8c66165f1ad9780102f26768bcd8f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 14 Jul 2016 20:34:00 +0200 Subject: [PATCH] re PR c/71858 (Surprising suggestions for misspellings) PR c/71858 * c-decl.c (lookup_name_fuzzy): Ignore binding->invisible. * gcc.dg/spellcheck-identifiers.c (snprintf): Declare. * gcc.dg/spellcheck-identifiers-2.c: New test. * gcc.dg/diagnostic-token-ranges.c (nanl): Declare. * c-c++-common/attributes-1.c: Adjust dg-prune-output. From-SVN: r238352 --- gcc/c/ChangeLog | 5 +++ gcc/c/c-decl.c | 2 +- gcc/testsuite/ChangeLog | 8 +++++ gcc/testsuite/c-c++-common/attributes-1.c | 2 +- .../gcc.dg/diagnostic-token-ranges.c | 2 ++ .../gcc.dg/spellcheck-identifiers-2.c | 33 +++++++++++++++++++ gcc/testsuite/gcc.dg/spellcheck-identifiers.c | 2 +- 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/spellcheck-identifiers-2.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 96dbf6b922c..6d35693cb2f 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2016-07-14 Jakub Jelinek + + PR c/71858 + * c-decl.c (lookup_name_fuzzy): Ignore binding->invisible. + 2016-07-12 Trevor Saunders * c-parser.c (c_parser_generic_selection): Make type of variable diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index c173796b438..e2e0f640b0a 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -4021,7 +4021,7 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind) for (c_scope *scope = current_scope; scope; scope = scope->outer) for (c_binding *binding = scope->bindings; binding; binding = binding->prev) { - if (!binding->id) + if (!binding->id || binding->invisible) continue; /* Don't use bindings from implicitly declared functions, as they were likely misspellings themselves. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b0c7b8a1b5..9585de48e79 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2016-07-14 Jakub Jelinek + + PR c/71858 + * gcc.dg/spellcheck-identifiers.c (snprintf): Declare. + * gcc.dg/spellcheck-identifiers-2.c: New test. + * gcc.dg/diagnostic-token-ranges.c (nanl): Declare. + * c-c++-common/attributes-1.c: Adjust dg-prune-output. + 2016-07-14 Jakub Jelinek PR tree-optimization/71872 diff --git a/gcc/testsuite/c-c++-common/attributes-1.c b/gcc/testsuite/c-c++-common/attributes-1.c index c348526b0d4..c76339ff680 100644 --- a/gcc/testsuite/c-c++-common/attributes-1.c +++ b/gcc/testsuite/c-c++-common/attributes-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-prune-output "undeclared here \\(not in a function\\); did you mean .carg..|\[^\n\r\]* was not declared in this scope" } */ +/* { dg-prune-output "undeclared here \\(not in a function\\); did you mean .char..|\[^\n\r\]* was not declared in this scope" } */ void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,bar))); /* { dg-warning "outside range" } */ void* my_realloc(void*, unsigned) __attribute__((alloc_size(bar))); /* { dg-warning "outside range" } */ diff --git a/gcc/testsuite/gcc.dg/diagnostic-token-ranges.c b/gcc/testsuite/gcc.dg/diagnostic-token-ranges.c index 19399490c04..20ceff517f9 100644 --- a/gcc/testsuite/gcc.dg/diagnostic-token-ranges.c +++ b/gcc/testsuite/gcc.dg/diagnostic-token-ranges.c @@ -2,6 +2,8 @@ /* Verify that various diagnostics show source code ranges. */ +long double nanl (const char *); + /* These ones merely use token ranges; they don't use tree ranges. */ void undeclared_identifier (void) diff --git a/gcc/testsuite/gcc.dg/spellcheck-identifiers-2.c b/gcc/testsuite/gcc.dg/spellcheck-identifiers-2.c new file mode 100644 index 00000000000..ad6e9d3191d --- /dev/null +++ b/gcc/testsuite/gcc.dg/spellcheck-identifiers-2.c @@ -0,0 +1,33 @@ +/* PR c/71858 */ +/* Make sure anticipated builtins are not considered before they are declared. */ +/* { dg-do compile } */ +/* { dg-options "-Wimplicit-function-declaration -fdiagnostics-show-caret" } */ + +int sscafn (const char *, const char *, ...); + +int +test_1 (const char *p) +{ + int i; + return ssacnf (p, "%d", &i); /* { dg-warning "10: implicit declaration of function .ssacnf.; did you mean .sscafn.?" } */ + /* { dg-begin-multiline-output "" } + return ssacnf (p, "%d", &i); + ^~~~~~ + sscafn + { dg-end-multiline-output "" } */ +} + +int scafn (const char *, ...); +int scanf (const char *, ...); + +int +test_2 (void) +{ + int i; + return sacnf ("%d", &i); /* { dg-warning "10: implicit declaration of function .sacnf.; did you mean .scanf.?" } */ + /* { dg-begin-multiline-output "" } + return sacnf ("%d", &i); + ^~~~~ + scanf + { dg-end-multiline-output "" } */ +} diff --git a/gcc/testsuite/gcc.dg/spellcheck-identifiers.c b/gcc/testsuite/gcc.dg/spellcheck-identifiers.c index 22a12d0fa1c..063e3f9eda1 100644 --- a/gcc/testsuite/gcc.dg/spellcheck-identifiers.c +++ b/gcc/testsuite/gcc.dg/spellcheck-identifiers.c @@ -121,7 +121,7 @@ test_6 (enum foo f) } } -/* Verify that we offer names of builtins as suggestions. */ +int snprintf (char *, __SIZE_TYPE__, const char *, ...); void test_7 (int i, int j) -- 2.30.2