diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 50614cf1f68fe2162c6d1eed12e3b45c2225f787..421840397533bf4866b7e5c7af1a22441b0336a7 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2020-05-22 Mark Wielaard <mark@klomp.org> + + * known-headers.cc (get_stdlib_header_for_name): Return + "<stdbool.h>" for "bool", "true" or "false" when STDLIB_C and + flag_isoc99. + 2020-05-20 Nathan Sidwell <nathan@acm.org> * c-common.c (try_to_locate_new_include_insertion_point): Revert change. diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index a21166860c0f952aa6f5a0a0bdd3f3e548797597..183ce2834afd707bc30b5bf3979a419c00efd99d 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -158,6 +158,14 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib) for (size_t i = 0; i < num_hints; i++) if (strcmp (name, hints[i].name) == 0) return hints[i].header[lib]; + + /* Only for C99 and higher. */ + if (lib == STDLIB_C && flag_isoc99) + if (strcmp (name, "bool") == 0 + || strcmp (name, "true") == 0 + || strcmp (name, "false") == 0) + return "<stdbool.h>"; + return NULL; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bedaf9aa73556153c52e1d6c0158ee86ef2778d5..cb3a2d1fa6fa08e8fd59dfdbfd3a986c9efccb8f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-05-22 Mark Wielaard <mark@klomp.org> + + * gcc.dg/spellcheck-stdbool.c: New test. + 2020-05-22 Mark Wielaard <mark@klomp.org> * gcc.dg/analyzer/signal-exit.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/spellcheck-stdbool.c b/gcc/testsuite/gcc.dg/spellcheck-stdbool.c new file mode 100644 index 0000000000000000000000000000000000000000..01f12da35cfe9367f6f785c2a1c548b84bded57a --- /dev/null +++ b/gcc/testsuite/gcc.dg/spellcheck-stdbool.c @@ -0,0 +1,17 @@ +/* { dg-options "-std=c99" } */ +/* Missing <stdbool.h>. */ + +bool b; /* { dg-error "unknown type name 'bool'" } */ +/* { dg-message "'bool' is defined in header '<stdbool.h>'; did you forget to '#include <stdbool.h>'?" "" { target *-*-* } .-1 } */ + +int test_true (void) +{ + return true; /* { dg-error "'true' undeclared" } */ + /* { dg-message "'true' is defined in header '<stdbool.h>'; did you forget to '#include <stdbool.h>'?" "" { target *-*-* } .-1 } */ +} + +int test_false (void) +{ + return false; /* { dg-error "'false' undeclared" } */ + /* { dg-message "'false' is defined in header '<stdbool.h>'; did you forget to '#include <stdbool.h>'?" "" { target *-*-* } .-1 } */ +}