Re: [PATCH] Suggest including or for [u]int[8|16|32|64]_t

2020-05-22 Thread David Malcolm via Gcc-patches
On Thu, 2020-05-21 at 00:27 +0200, Mark Wielaard wrote:
> Plus [u]intptr_t and associated constants.
> 
> Refactor the bool, true, false,  code so it fits into the
> new table based design.
> 
> gcc/c-family/ChangeLog:
> 
>   * known-headers.cc (get_stdlib_header_for_name): Add a new
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/spellcheck-stdint.c: New test.
>   * g++.dg/spellcheck-stdint.C: Likewise.

Looks good to me

Thanks
Dave



[PATCH] Suggest including or for [u]int[8|16|32|64]_t

2020-05-20 Thread Mark Wielaard
Plus [u]intptr_t and associated constants.

Refactor the bool, true, false,  code so it fits into the
new table based design.

gcc/c-family/ChangeLog:

* known-headers.cc (get_stdlib_header_for_name): Add a new

gcc/testsuite/ChangeLog:

* gcc.dg/spellcheck-stdint.c: New test.
* g++.dg/spellcheck-stdint.C: Likewise.
---
 gcc/c-family/known-headers.cc| 42 ---
 gcc/testsuite/g++.dg/spellcheck-stdint.C | 68 
 gcc/testsuite/gcc.dg/spellcheck-stdint.c | 62 +
 3 files changed, 166 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/spellcheck-stdint.C
 create mode 100644 gcc/testsuite/gcc.dg/spellcheck-stdint.c

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 183ce2834afd..1e2bf49c439a 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -159,12 +159,42 @@ get_stdlib_header_for_name (const char *name, enum stdlib 
lib)
 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 "";
+  static const stdlib_hint c99_cxx11_hints[] = {
+/* .  Defined natively in C++.  */
+{"bool", {"", NULL} },
+{"true", {"", NULL} },
+{"false", {"", NULL} },
+
+/*  and .  */
+{"int8_t", {"", ""} },
+{"uint8_t", {"", ""} },
+{"int16_t", {"", ""} },
+{"uint16_t", {"", ""} },
+{"int32_t", {"", ""} },
+{"uint32_t", {"", ""} },
+{"int64_t", {"", ""} },
+{"uint64_t", {"", ""} },
+{"intptr_t", {"", ""} },
+{"uintptr_t", {"", ""} },
+{"INT8_MAX", {"", ""} },
+{"INT16_MAX", {"", ""} },
+{"INT32_MAX", {"", ""} },
+{"INT64_MAX", {"", ""} },
+{"UINT8_MAX", {"", ""} },
+{"UINT16_MAX", {"", ""} },
+{"UINT32_MAX", {"", ""} },
+{"UINT64_MAX", {"", ""} },
+{"INTPTR_MAX", {"", ""} },
+{"UINTPTR_MAX", {"", ""} }
+  };
+
+  const size_t num_c99_cxx11_hints = sizeof (c99_cxx11_hints)
+/ sizeof (c99_cxx11_hints[0]);
+  if ((lib == STDLIB_C && flag_isoc99)
+  || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
+for (size_t i = 0; i < num_c99_cxx11_hints; i++)
+  if (strcmp (name, c99_cxx11_hints[i].name) == 0)
+   return c99_cxx11_hints[i].header[lib];
 
   return NULL;
 }
diff --git a/gcc/testsuite/g++.dg/spellcheck-stdint.C 
b/gcc/testsuite/g++.dg/spellcheck-stdint.C
new file mode 100644
index ..b9ce3b7aed81
--- /dev/null
+++ b/gcc/testsuite/g++.dg/spellcheck-stdint.C
@@ -0,0 +1,68 @@
+/* { dg-options "-std=c++11" } */
+/* Missing .  */
+
+char c = INT8_MAX; // { dg-error "'INT8_MAX' was not declared" }
+// { dg-message "'INT8_MAX' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+
+short s = INT16_MAX; // { dg-error "'INT16_MAX' was not declared" }
+// { dg-message "'INT16_MAX' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+
+int i = INT32_MAX; // { dg-error "'INT32_MAX' was not declared" }
+// { dg-message "'INT32_MAX' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+
+long l = INT64_MAX; // { dg-error "'INT64_MAX' was not declared" }
+// { dg-message "'INT64_MAX' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+
+intptr_t test_intptr (void) // { dg-error "'intptr_t' does not name a type" }
+// { dg-message "'intptr_t' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+{
+  return 0;
+}
+
+int test_intptr_max (void)
+{
+  return (int) INTPTR_MAX; // { dg-error "'INTPTR_MAX' was not declared" }
+// { dg-message "'INTPTR_MAX' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+}
+
+uintptr_t test_uintptr (void) // { dg-error "'uintptr_t' does not name a type" 
}
+// { dg-message "'uintptr_t' is defined in header ''; did you forget 
to '#include '?" "" { target *-*-* } .-1 }
+{
+  return 0;
+}
+
+unsigned int test_uintptr_max (void)
+{
+  return (unsigned int) UINTPTR_MAX; // { dg-error "'UINTPTR_MAX' was not 
declared" }
+// { dg-message "'UINTPTR_MAX' is defined in header ''; did you 
forget to '#include '?" "" { target *-*-* } .-1 }
+}
+
+int8_t i8; // { dg-error "'int8_t' does not name a type" }
+// { dg-message "'int8_t' is defined in header ''; did you forget to 
'#include '?" "" { target *-*-* } .-1 }
+int16_t i16; // { dg-error "'int16_t' does not name a type" }
+// { dg-message "'int16_t' is defined in header ''; did you forget to 
'#include '?" "" { target *-*-* } .-1 }
+int32_t i32; // { dg-error "'int32_t' does not name a type" }
+// { dg-message "'int32_t' is defined in header ''; did you forget to 
'#include '?" "" { target *-*-* } .-1 }
+int64_t i64; // { dg-error