re PR c/71858 (Surprising suggestions for misspellings)
authorJakub Jelinek <jakub@redhat.com>
Fri, 15 Jul 2016 10:40:39 +0000 (12:40 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 15 Jul 2016 10:40:39 +0000 (12:40 +0200)
PR c/71858
* c-common.h (enum lookup_name_fuzzy_kind): Add
FUZZY_LOOKUP_FUNCTION_NAME.

* c-decl.c (implicit_decl_warning): Use FUZZY_LOOKUP_FUNCTION_NAME
instead of FUZZY_LOOKUP_NAME.
(lookup_name_fuzzy): For FUZZY_LOOKUP_FUNCTION_NAME consider
FUNCTION_DECLs, {VAR,PARM}_DECLs function pointers and macros.

* gcc.dg/spellcheck-identifiers-3.c: New test.

From-SVN: r238369

gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/spellcheck-identifiers-3.c [new file with mode: 0644]

index 9c002f61fc610d69e3fc3eb12a9a51f80295fab0..46e45091dcbc269fee75996fcc17778071e9d81f 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/71858
+       * c-common.h (enum lookup_name_fuzzy_kind): Add
+       FUZZY_LOOKUP_FUNCTION_NAME.
+
 2016-07-08  Jason Merrill  <jason@redhat.com>
 
        P0145: Refining Expression Order for C++.
index 3ad5400458efb0e9dde10519b6892254cbd5be07..0f068e6b556ab6d52f4cf7d156ad81b0c43fd6e2 100644 (file)
@@ -994,6 +994,9 @@ enum lookup_name_fuzzy_kind {
   /* Names of types.  */
   FUZZY_LOOKUP_TYPENAME,
 
+  /* Names of function decls.  */
+  FUZZY_LOOKUP_FUNCTION_NAME,
+
   /* Any name.  */
   FUZZY_LOOKUP_NAME
 };
index 6d35693cb2fdad6088d21809f402b80b8ed6bfb4..968d942c7bee9eb084a64ab9b3fa92d8e02d8c53 100644 (file)
@@ -1,3 +1,11 @@
+2016-07-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/71858
+       * c-decl.c (implicit_decl_warning): Use FUZZY_LOOKUP_FUNCTION_NAME
+       instead of FUZZY_LOOKUP_NAME.
+       (lookup_name_fuzzy): For FUZZY_LOOKUP_FUNCTION_NAME consider
+       FUNCTION_DECLs, {VAR,PARM}_DECLs function pointers and macros.
+
 2016-07-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/71858
index e2e0f640b0a389582b21c4054dc8709229f344e5..955c0e8da73b06a4718fce48508a32696eab927b 100644 (file)
@@ -3090,7 +3090,7 @@ implicit_decl_warning (location_t loc, tree id, tree olddecl)
       bool warned;
       tree hint = NULL_TREE;
       if (!olddecl)
-       hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME);
+       hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME);
 
       if (flag_isoc99)
        if (hint)
@@ -4028,9 +4028,30 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind)
        if (TREE_CODE (binding->decl) == FUNCTION_DECL)
          if (C_DECL_IMPLICIT (binding->decl))
            continue;
-       if (kind == FUZZY_LOOKUP_TYPENAME)
-         if (TREE_CODE (binding->decl) != TYPE_DECL)
-           continue;
+       switch (kind)
+         {
+         case FUZZY_LOOKUP_TYPENAME:
+           if (TREE_CODE (binding->decl) != TYPE_DECL)
+             continue;
+           break;
+
+         case FUZZY_LOOKUP_FUNCTION_NAME:
+           if (TREE_CODE (binding->decl) != FUNCTION_DECL)
+             {
+               /* Allow function pointers.  */
+               if ((VAR_P (binding->decl)
+                    || TREE_CODE (binding->decl) == PARM_DECL)
+                   && TREE_CODE (TREE_TYPE (binding->decl)) == POINTER_TYPE
+                   && (TREE_CODE (TREE_TYPE (TREE_TYPE (binding->decl)))
+                       == FUNCTION_TYPE))
+                 break;
+               continue;
+             }
+           break;
+
+         default:
+           break;
+         }
        bm.consider (binding->id);
       }
 
index 5ad50f944d8808d5f1e47100aea3f0e6c36b16b3..939fef3af757ebbdf862baa04329f77c3a3596fc 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/71858
+       * gcc.dg/spellcheck-identifiers-3.c: New test.
+
 2016-07-15  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/71807
diff --git a/gcc/testsuite/gcc.dg/spellcheck-identifiers-3.c b/gcc/testsuite/gcc.dg/spellcheck-identifiers-3.c
new file mode 100644 (file)
index 0000000..94f4078
--- /dev/null
@@ -0,0 +1,45 @@
+/* PR c/71858 */
+/* Only consider function names, function pointers and macros for implicit function declarations.  */
+/* { dg-do compile } */
+/* { dg-options "-Wimplicit-function-declaration -fdiagnostics-show-caret" } */
+
+void fn1abcd (void);
+
+void
+test_1 (int fn1bacd)
+{
+  fn1badc (); /* { dg-warning "3: implicit declaration of function .fn1badc.; did you mean .fn1abcd.?" } */
+  /* { dg-begin-multiline-output "" }
+   fn1badc ();
+   ^~~~~~~
+   fn1abcd
+   { dg-end-multiline-output "" } */
+}
+
+void fn2efgh (void);
+void (*fn2efhg) (void);
+
+void
+test_2 (void)
+{
+  fn2fehg (); /* { dg-warning "3: implicit declaration of function .fn2fehg.; did you mean .fn2efhg.?" } */
+  /* { dg-begin-multiline-output "" }
+   fn2fehg ();
+   ^~~~~~~
+   fn2efhg
+   { dg-end-multiline-output "" } */
+}
+
+void fn3ijkl (void);
+typedef int fn3ijlk;
+
+void
+test_3 (void)
+{
+  fn3jilk (); /* { dg-warning "3: implicit declaration of function .fn3jilk.; did you mean .fn3ijkl.?" } */
+  /* { dg-begin-multiline-output "" }
+   fn3jilk ();
+   ^~~~~~~
+   fn3ijkl
+   { dg-end-multiline-output "" } */
+}