aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-06-29 23:41:46 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-06-30 17:46:16 +0100
commitd489ec082ea214109ff54071410f8cd00344e654 (patch)
treeeebe6ece87d5ec6e0c0d8f0d436c5d01c5242a60
parent8a8ee37a3325f1009034245676ef4e482c0444a2 (diff)
downloadgcc-d489ec082ea214109ff54071410f8cd00344e654.zip
gcc-d489ec082ea214109ff54071410f8cd00344e654.tar.gz
gcc-d489ec082ea214109ff54071410f8cd00344e654.tar.bz2
c-family: Add <time.h> names to diagnostics for known headers
gcc/c-family/ChangeLog: * known-headers.cc (get_stdlib_header_for_name): Add <time.h> names. gcc/testsuite/ChangeLog: * g++.dg/spellcheck-stdlib.C: Check <ctime> types and functions.
-rw-r--r--gcc/c-family/known-headers.cc14
-rw-r--r--gcc/testsuite/g++.dg/spellcheck-stdlib.C29
2 files changed, 43 insertions, 0 deletions
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 01c86b2..9c25617 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -199,6 +199,20 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
{"WINT_MAX", {"<stdint.h>", "<cstdint>"} },
{"WINT_MIN", {"<stdint.h>", "<cstdint>"} },
+ /* <time.h>. */
+ {"asctime", {"<time.h>", "<ctime>"} },
+ {"clock", {"<time.h>", "<ctime>"} },
+ {"clock_t", {"<time.h>", "<ctime>"} },
+ {"ctime", {"<time.h>", "<ctime>"} },
+ {"difftime", {"<time.h>", "<ctime>"} },
+ {"gmtime", {"<time.h>", "<ctime>"} },
+ {"localtime", {"<time.h>", "<ctime>"} },
+ {"mktime", {"<time.h>", "<ctime>"} },
+ {"strftime", {"<time.h>", "<ctime>"} },
+ {"time", {"<time.h>", "<ctime>"} },
+ {"time_t", {"<time.h>", "<ctime>"} },
+ {"tm", {"<time.h>", "<ctime>"} },
+
/* <wchar.h>. */
{"WCHAR_MAX", {"<wchar.h>", "<cwchar>"} },
{"WCHAR_MIN", {"<wchar.h>", "<cwchar>"} }
diff --git a/gcc/testsuite/g++.dg/spellcheck-stdlib.C b/gcc/testsuite/g++.dg/spellcheck-stdlib.C
index 87736b2..7a70641 100644
--- a/gcc/testsuite/g++.dg/spellcheck-stdlib.C
+++ b/gcc/testsuite/g++.dg/spellcheck-stdlib.C
@@ -158,6 +158,35 @@ void test_cstdlib (void *q)
// { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
}
+/* Missing <ctime>. */
+
+void test_ctime (void *q, long s, double d)
+{
+ clock_t c; // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ time_t t; // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ tm t2; // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ d = difftime (0, 0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ s = mktime (q); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ s = time (0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ q = asctime (0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ q = ctime (0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ q = gmtime (0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ q = localtime (0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+ char c[2];
+ strftime (c, 2, "", 0); // { dg-error "was not declared" }
+ // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
+}
+
/* Verify that we don't offer suggestions to stdlib globals names when
there's an explicit namespace. */