diff options
author | David Malcolm <dmalcolm@redhat.com> | 2019-01-31 18:09:29 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2019-01-31 18:09:29 +0000 |
commit | ec2be203d1d8c5cd690cc1444303a2ca9187e962 (patch) | |
tree | 353a626c0687248a7da4d78198b3f10714c0283a /gcc/c-family/known-headers.cc | |
parent | 636ecb78a36df20232be05fd4fa2bdbea67c5551 (diff) | |
download | gcc-ec2be203d1d8c5cd690cc1444303a2ca9187e962.zip gcc-ec2be203d1d8c5cd690cc1444303a2ca9187e962.tar.gz gcc-ec2be203d1d8c5cd690cc1444303a2ca9187e962.tar.bz2 |
Fix bogus fix-it for FLT_MAX (PR c/89122)
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
Diffstat (limited to 'gcc/c-family/known-headers.cc')
-rw-r--r-- | gcc/c-family/known-headers.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index e3dcf73..c222f30 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -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>"} }, |