Fix bogus fix-it for FLT_MAX (PR c/89122)
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 31 Jan 2019 18:09:29 +0000 (18:09 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 31 Jan 2019 18:09:29 +0000 (18:09 +0000)
PR c/89122 reports that we emit a bogus fix-it hint for the case where
the code uses FLT_MAX, but has included <limits.h> rather than <float.h>:

x.c:3:11: error: 'FLT_MAX' undeclared here (not in a function); did you
  mean 'INT_MAX'?
    3 | float f = FLT_MAX;
      |           ^~~~~~~
      |           INT_MAX

This patch adds some knowledge of <float.h> (and <cfloat>) to
known-headers.cc, fixing the issue:

x.c:3:11: error: 'FLT_MAX' undeclared here (not in a function)
    3 | float f = FLT_MAX;
      |           ^~~~~~~
x.c:2:1: note: 'FLT_MAX' is defined in header '<float.h>'; did you forget
  to '#include <float.h>'?
    1 | #include <limits.h>
  +++ |+#include <float.h>
    2 |

gcc/c-family/ChangeLog:
PR c/89122
* known-headers.cc (get_stdlib_header_for_name): Add
{FLT|DBL|LDBL}_{MAX|MIN} to "hints" array.

gcc/testsuite/ChangeLog:
PR c/89122
* g++.dg/spellcheck-stdlib.C (test_FLT_MAX): New test.
* gcc.dg/spellcheck-stdlib.c (test_FLT_MAX): New test.

From-SVN: r268426

gcc/c-family/ChangeLog
gcc/c-family/known-headers.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/spellcheck-stdlib.C
gcc/testsuite/gcc.dg/spellcheck-stdlib.c

index 25c5323..dd1173f 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-31  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c/89122
+       * known-headers.cc (get_stdlib_header_for_name): Add
+       {FLT|DBL|LDBL}_{MAX|MIN} to "hints" array.
+
 2019-01-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR libstdc++/88170
index e3dcf73..c222f30 100644 (file)
@@ -84,6 +84,14 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"ULONG_MAX", {"<limits.h>", "<climits>"} },
     {"USHRT_MAX", {"<limits.h>", "<climits>"} },
 
+    /* <float.h> and <cfloat>.  */
+    {"DBL_MAX", {"<float.h>", "<cfloat>"} },
+    {"DBL_MIN", {"<float.h>", "<cfloat>"} },
+    {"FLT_MAX", {"<float.h>", "<cfloat>"} },
+    {"FLT_MIN", {"<float.h>", "<cfloat>"} },
+    {"LDBL_MAX", {"<float.h>", "<cfloat>"} },
+    {"LDBL_MIN", {"<float.h>", "<cfloat>"} },
+
     /* <stdarg.h> and <cstdarg>.  */
     {"va_list", {"<stdarg.h>", "<cstdarg>"} },
 
index 5197926..25cf4cd 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-31  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c/89122
+       * g++.dg/spellcheck-stdlib.C (test_FLT_MAX): New test.
+       * gcc.dg/spellcheck-stdlib.c (test_FLT_MAX): New test.
+
 2019-01-31  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/89135
index 11a4e3e..31e91fe 100644 (file)
@@ -77,6 +77,11 @@ int test_INT_MAX (void)
   // { dg-message "'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?" "" { target *-*-* } INT_MAX_line }
 }
 
+/* Missing <cfloat>.  */
+float test_FLT_MAX = FLT_MAX; // { dg-line FLT_MAX_line }
+// { dg-error "'FLT_MAX' was not declared" "" { target *-*-* } FLT_MAX_line }
+// { dg-message "'FLT_MAX' is defined in header '<cfloat>'; did you forget to '#include <cfloat>'?" "" { target *-*-* } FLT_MAX_line }
+
 /* Missing <cstring>.  */
 
 void test_cstring (char *dest, char *src)
index 7474c9a..1ae3b5e 100644 (file)
@@ -62,3 +62,8 @@ int test_INT_MAX (void)
   /* { dg-bogus "__INT_MAX__" "" { target *-*-* } INT_MAX_line } */
   /* { dg-message "'INT_MAX' is defined in header '<limits.h>'; did you forget to '#include <limits.h>'?" "" { target *-*-* } INT_MAX_line } */
 }
+
+/* Missing <float.h>.  */
+float test_FLT_MAX = FLT_MAX; /* { dg-line FLT_MAX_line } */
+/* { dg-error "'FLT_MAX' undeclared" "" { target *-*-* } FLT_MAX_line } */
+/* { dg-message "'FLT_MAX' is defined in header '<float.h>'; did you forget to '#include <float.h>'?" "" { target *-*-* } FLT_MAX_line } */