public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c-family: Add <time.h> names to diagnostics for known headers
Date: Thu, 30 Jun 2022 11:15:37 -0400	[thread overview]
Message-ID: <Yr2+Gc9te1i8C83d@redhat.com> (raw)
In-Reply-To: <20220630151142.1242987-1-jwakely@redhat.com>

On Thu, Jun 30, 2022 at 04:11:42PM +0100, Jonathan Wakely via Gcc-patches wrote:
> I recently changed <string> to no longer include an unnecessary header,
> which meant it no longer includes <pthread.h>, which means it no longer
> includes <time.h>. This resulted in some build failures:
> https://issues.apache.org/jira/browse/LUCENE-10630
> https://github.com/openSUSE/libzypp/pull/405
> 
> And that revealed that we don't suggest the right header for those
> functions. Fixed like so.
> 
> Tested x86_64-linux. OK for trunk?

Ok, thanks.
 
> -- >8 --
> 
> 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.
> ---
>  gcc/c-family/known-headers.cc            | 14 ++++++++++++
>  gcc/testsuite/g++.dg/spellcheck-stdlib.C | 29 ++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
> index 01c86b27dc8..9c256173b82 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 87736b25e54..7a70641e3ae 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.  */
>  
> -- 
> 2.36.1
> 

Marek


  reply	other threads:[~2022-06-30 15:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 15:11 Jonathan Wakely
2022-06-30 15:15 ` Marek Polacek [this message]
2022-07-04 16:25   ` Jonathan Wakely
2022-07-05 14:58     ` Marek Polacek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yr2+Gc9te1i8C83d@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).