From patchwork Thu Jun 30 15:11:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 55608 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 868373841448 for ; Thu, 30 Jun 2022 15:12:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 868373841448 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656601937; bh=rTsIwgn2GmHv0D30hmMWWSS/nfRekmpumsMT6FlG/ZE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cz3ftD0InVUTLlW7Q9rukiNz7W2DI/BuJt7uiVdZVCHZLOxl1/Ifk7Gaui+AbdSrI BqGZPdV/C78PH9O4izEttUQg6Hev7nRT0Kb6QfT8ySsuQbsEk+narA+pRb9s0XnPG4 SLIyWnoFfdZFS56yjb/xOI3ePWFERZXFb17lmhXg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A37C538460AE for ; Thu, 30 Jun 2022 15:11:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A37C538460AE Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-454-ArBcJ8XcPEyK-hSMF4zF9A-1; Thu, 30 Jun 2022 11:11:44 -0400 X-MC-Unique: ArBcJ8XcPEyK-hSMF4zF9A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DAE8B1C0F685 for ; Thu, 30 Jun 2022 15:11:43 +0000 (UTC) Received: from localhost (unknown [10.33.36.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id A208D40CF8EF; Thu, 30 Jun 2022 15:11:43 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c-family: Add names to diagnostics for known headers Date: Thu, 30 Jun 2022 16:11:42 +0100 Message-Id: <20220630151142.1242987-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" I recently changed to no longer include an unnecessary header, which meant it no longer includes , which means it no longer includes . 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? -- >8 -- gcc/c-family/ChangeLog: * known-headers.cc (get_stdlib_header_for_name): Add names. gcc/testsuite/ChangeLog: * g++.dg/spellcheck-stdlib.C: Check 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", {"", ""} }, {"WINT_MIN", {"", ""} }, + /* . */ + {"asctime", {"", ""} }, + {"clock", {"", ""} }, + {"clock_t", {"", ""} }, + {"ctime", {"", ""} }, + {"difftime", {"", ""} }, + {"gmtime", {"", ""} }, + {"localtime", {"", ""} }, + {"mktime", {"", ""} }, + {"strftime", {"", ""} }, + {"time", {"", ""} }, + {"time_t", {"", ""} }, + {"tm", {"", ""} }, + /* . */ {"WCHAR_MAX", {"", ""} }, {"WCHAR_MIN", {"", ""} } 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 '" "" { target *-*-* } .-1 } } +/* Missing . */ + +void test_ctime (void *q, long s, double d) +{ + clock_t c; // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + time_t t; // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + tm t2; // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + d = difftime (0, 0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + s = mktime (q); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + s = time (0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + q = asctime (0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + q = ctime (0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + q = gmtime (0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + q = localtime (0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + char c[2]; + strftime (c, 2, "", 0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } +} + /* Verify that we don't offer suggestions to stdlib globals names when there's an explicit namespace. */