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-Tag: upstream/12.2.0~26446 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec2be203d1d8c5cd690cc1444303a2ca9187e962;p=platform%2Fupstream%2Fgcc.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 25c5323..dd1173f 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 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", {"", ""} }, {"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 5197926..25cf4cd 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 11a4e3e..31e91fe 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 7474c9a..1ae3b5e 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 } */