From: David Malcolm Date: Thu, 31 Jan 2019 18:09:29 +0000 (+0000) Subject: Fix bogus fix-it for FLT_MAX (PR c/89122) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ec2be203d1d8c5cd690cc1444303a2ca9187e962;p=gcc.git 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 rather than : 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 (and ) 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 ''; did you forget to '#include '? 1 | #include +++ |+#include 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 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 25c5323f6db..dd1173f0487 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2019-01-31 David Malcolm + + 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 PR libstdc++/88170 diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index e3dcf73fd70..c222f306c84 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", {"", ""} }, {"USHRT_MAX", {"", ""} }, + /* and . */ + {"DBL_MAX", {"", ""} }, + {"DBL_MIN", {"", ""} }, + {"FLT_MAX", {"", ""} }, + {"FLT_MIN", {"", ""} }, + {"LDBL_MAX", {"", ""} }, + {"LDBL_MIN", {"", ""} }, + /* and . */ {"va_list", {"", ""} }, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5197926d3d0..25cf4cdafaa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-01-31 David Malcolm + + 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 PR tree-optimization/89135 diff --git a/gcc/testsuite/g++.dg/spellcheck-stdlib.C b/gcc/testsuite/g++.dg/spellcheck-stdlib.C index 11a4e3e8c41..31e91fe8d1b 100644 --- a/gcc/testsuite/g++.dg/spellcheck-stdlib.C +++ b/gcc/testsuite/g++.dg/spellcheck-stdlib.C @@ -77,6 +77,11 @@ int test_INT_MAX (void) // { dg-message "'INT_MAX' is defined in header ''; did you forget to '#include '?" "" { target *-*-* } INT_MAX_line } } +/* Missing . */ +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 ''; did you forget to '#include '?" "" { target *-*-* } FLT_MAX_line } + /* Missing . */ void test_cstring (char *dest, char *src) diff --git a/gcc/testsuite/gcc.dg/spellcheck-stdlib.c b/gcc/testsuite/gcc.dg/spellcheck-stdlib.c index 7474c9a5b03..1ae3b5e33ab 100644 --- a/gcc/testsuite/gcc.dg/spellcheck-stdlib.c +++ b/gcc/testsuite/gcc.dg/spellcheck-stdlib.c @@ -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 ''; did you forget to '#include '?" "" { target *-*-* } INT_MAX_line } */ } + +/* Missing . */ +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 ''; did you forget to '#include '?" "" { target *-*-* } FLT_MAX_line } */