From patchwork Wed Feb 28 01:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oskari Pirhonen X-Patchwork-Id: 207561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3067458dyb; Tue, 27 Feb 2024 17:14:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWe9RWwt967xp14/kHFnnpmR5AKuvXaYt9XrPAm8Ax0VnXhNZwbhYtj5ydf0XEN0p83lbddT4BUd60C7I4pPp0L7/Wy/g== X-Google-Smtp-Source: AGHT+IFGQ9UR0YQwTuJHQ+CU5dKwfgZ3tTmEUFcNTfC3s4fgcla/BxZZ4eKM1Hn2CunCdoRIzBpH X-Received: by 2002:a05:6214:20a5:b0:68f:71ad:6502 with SMTP id 5-20020a05621420a500b0068f71ad6502mr4310137qvd.41.1709082867145; Tue, 27 Feb 2024 17:14:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709082867; cv=pass; d=google.com; s=arc-20160816; b=fN+CRYD80GcpLsvSkCJYeCW25pBzI9ewwzgoi5MXgWzFGrhovI83T5lcnHXGuY9Mpy 5J4OwrmDolyvOsMFbSgLS8VEuKsAPnAuWu0XAJFGvVWI3nphcxe8zD48yA9Cj0Bo9FtJ hNNgjz9isPPLR1AZZMqR31L7OEbAv7FHJo4XkgE+950VdLloGRI+dmULPqd7Z0mouKHc yCR+O/FmOHe94zOetKw0OBJimENBgJFbjZfRGQimXGdHEUOaC5bc37b20kBF+S10lx82 1DZoIQKp6UdpxVF1qDo+UsY56bN3qsByUjVX0dNvsoNLCVfNroYsYEC/6v6Z4xuE6jUz o8hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=n617sPKS4lgIEq4JwGtPOIEEAsR02GmgjA3n9iRBPyI=; fh=DY76WWugxFSSEiow8Voo+cMAhaQ2VIY1w+QHK6Ta6KU=; b=ouPE3pXxLY8fNUP6OnCdBRqVOWX4DpIDGVzUeINTbNGdUQboEegfoQDDXqQw/qat4i xek7T+HKsp/bwHNuonnney+T+rNxwiGDzMrR5XpHwRyS/jfGVKgG00a0pV2sF6i06mh0 rAX0Nz71jK+PH4WVd2yZfquHYoZd1R0WkJyK3S2ME/RzA4QX5zwp5/UFBtTz2suLO+CV 5Few4NrjOlkzoD1++KL6iEDpOtjJ0ucl+xX7PPvKYab3xe6s9QLoFbTyI5/8y9f1F6Mv dIHWypz9vFkSXbJA297MoRut62Zw1hdUTQ7SqeiAFL8pXPgm9LSlm33xv401Ku4+MVY2 07DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FVMjx7Ge; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m10-20020a0562141bca00b0069017283bfesi4363025qvc.275.2024.02.27.17.14.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:14:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FVMjx7Ge; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC7443858C32 for ; Wed, 28 Feb 2024 01:14:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 4CDD33858D37 for ; Wed, 28 Feb 2024 01:13:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CDD33858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4CDD33858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709082820; cv=none; b=M6plMdWV4kBDfiI1N9jfZAyq1r8E/4AEz5Bwedz+/OcQvk0l2+CWa16awkaFryJbXu9kLDSz0Tyl/nPGEK2Ml1smW2y9y6z8OtkrfNtqxBmfqnLIUMdv7Dk1svCRjp+7GP+RzkO4myA4ns3FuC12qBkJmb5cTTHIJBqFQ2ee5zA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709082820; c=relaxed/simple; bh=NierrswsREVTrGbrwDBunQlTfuey1RaRkzn2ORKb6yI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=udpLg88cPA//o/WSaQp/FSbDRPGgwk4/mcGFrDocc7QFdC0Cgje0qtYRmnYRsef4wvTxw7M+lAuERmlW17dppeMWRExVWlroMMAlsqai73VPUwDGKMx3fJzjNMhIwQdEwLyq0XI6DEtfgMlNH92Ixgj/316iHL0bOPwhSUuQ3jA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a3ed9cae56fso64792366b.1 for ; Tue, 27 Feb 2024 17:13:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709082816; x=1709687616; darn=gcc.gnu.org; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=n617sPKS4lgIEq4JwGtPOIEEAsR02GmgjA3n9iRBPyI=; b=FVMjx7GeElzpUGgkTx6zzNc/DLzZsDezaZk2cBWA1EUqyzjTKgBHiSJVhOm6MZJ1Hn cVcGDfRzjplBSx9+5LI32l/zJJYg3PmKJ1iBOgKxeG6sbSKlb+F7npq97QtcwMdbNTOX h07DINzl2vKBuqtzxEF+qcXDWzfA4Hu9eRCcrBjYKUNiITqv4LM84XELxwhdtzJ3936k 189t5EKMGZ1VITUGOUfLIAR6PNXhLYpL1Z/pKgoMg4l2pqpakXxDAYFehHQONmecHFzp HYTXi5cp8mWBpiTS1O6aMsX33ZLp0CnY8OQpT6LpMG+MVE8SWnWIkLgUD9gLwDz1HPx6 hq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709082816; x=1709687616; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n617sPKS4lgIEq4JwGtPOIEEAsR02GmgjA3n9iRBPyI=; b=v1PtGtPbZRGGAiQQTVqjwq3rMBxgGnjbB4LrViBhkdubh5pRGx+2r8sMjvXhOI3ftS 2hYYVCL+JtoI6sfJIwk6uzA2yVb4GWYdKfM1YNu/E1xRgpWbsiKMnDO9LdyL97/DTyCw iK9XqXt73FSR6+F9PoLKOC/fQp4eGQd51N4hF8dT+UEmjFr0L62EK2RqcVVQDooaKQdm ZZlL4sZ8jYmUO5v3l1g5vJmxrrLeA0ft4381Lb6j8DsEX8rzlIO4VdcEXtHdB8G2XEUe a/M/iY7zYyYslIqe0PTGy8YDrk8oNYRc/8wYG+ubonCvxjrQDkSvw82hAOLMxtnZ1Q9+ 6wCA== X-Gm-Message-State: AOJu0YyyuasJQPZ5O9mMkQXVz0KgfWucIrvu6a3posA9fCfqd3T+/aGE JNpNJmUzWv4tpNFbxCt5Y5CK91m/4Yt/SxUn0dKmBKjghEKCUwmNOkCBxOP4 X-Received: by 2002:a17:906:c090:b0:a43:9d17:dfba with SMTP id f16-20020a170906c09000b00a439d17dfbamr909633ejz.31.1709082815870; Tue, 27 Feb 2024 17:13:35 -0800 (PST) Received: from dj3ntoo (30.sub-97-147-14.myvzw.com. [97.147.14.30]) by smtp.gmail.com with ESMTPSA id b16-20020a170906835000b00a4395e9debasm1283100ejy.201.2024.02.27.17.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:13:35 -0800 (PST) Date: Tue, 27 Feb 2024 19:13:30 -0600 From: Oskari Pirhonen To: gcc-patches@gcc.gnu.org Cc: dodji@redhat.com, dmalcolm@redhat.com Subject: [PATCH v2] C/C++: add hints for strerror Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792103276263120950 X-GMAIL-MSGID: 1792103276263120950 Add proper hints for implicit declaration of strerror. The results could be confusing depending on the other included headers. These example messages are from compiling a trivial program to print the string for an errno value. It only includes stdio.h (cstdio for C++). Before: $ /tmp/gcc-master/bin/gcc test.c -o test_c test.c: In function ‘main’: test.c:4:20: warning: implicit declaration of function ‘strerror’; did you mean ‘perror’? [-Wimplicit-function-declaration] 4 | printf("%s\n", strerror(0)); | ^~~~~~~~ | perror $ /tmp/gcc-master/bin/g++ test.cpp -o test_cpp test.cpp: In function ‘int main()’: test.cpp:4:20: error: ‘strerror’ was not declared in this scope; did you mean ‘stderr’? 4 | printf("%s\n", strerror(0)); | ^~~~~~~~ | stderr After: $ /tmp/gcc-known-headers/bin/gcc test.c -o test_c test.c: In function ‘main’: test.c:4:20: warning: implicit declaration of function ‘strerror’ [-Wimplicit-function-declaration] 4 | printf("%s\n", strerror(0)); | ^~~~~~~~ test.c:2:1: note: ‘strerror’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ 1 | #include +++ |+#include 2 | $ /tmp/gcc-known-headers/bin/g++ test.cpp -o test_cpp test.cpp: In function ‘int main()’: test.cpp:4:20: error: ‘strerror’ was not declared in this scope 4 | printf("%s\n", strerror(0)); | ^~~~~~~~ test.cpp:2:1: note: ‘strerror’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ 1 | #include +++ |+#include 2 | gcc/c-family/ChangeLog: * known-headers.cc (get_stdlib_header_for_name): Add strerror. gcc/testsuite/ChangeLog: * g++.dg/spellcheck-stdlib.C: Add check for strerror. * gcc.dg/spellcheck-stdlib-2.c: New test. Signed-off-by: Oskari Pirhonen --- v2: - check for error instead of warning in gcc.dg/spellcheck-stdlib-2.c - from linaro ci notification email gcc/c-family/known-headers.cc | 1 + gcc/testsuite/g++.dg/spellcheck-stdlib.C | 2 ++ gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c | 8 ++++++++ 3 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index dbc42eacde1..871fd714eb5 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -182,6 +182,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib) {"strchr", {"", ""} }, {"strcmp", {"", ""} }, {"strcpy", {"", ""} }, + {"strerror", {"", ""} }, {"strlen", {"", ""} }, {"strncat", {"", ""} }, {"strncmp", {"", ""} }, diff --git a/gcc/testsuite/g++.dg/spellcheck-stdlib.C b/gcc/testsuite/g++.dg/spellcheck-stdlib.C index fd0f3a9b8c9..33718b8034e 100644 --- a/gcc/testsuite/g++.dg/spellcheck-stdlib.C +++ b/gcc/testsuite/g++.dg/spellcheck-stdlib.C @@ -104,6 +104,8 @@ void test_cstring (char *dest, char *src) // { dg-message "'#include '" "" { target *-*-* } .-1 } strcpy(dest, "test"); // { dg-error "was not declared" } // { dg-message "'#include '" "" { target *-*-* } .-1 } + strerror(0); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } strlen("test"); // { dg-error "was not declared" } // { dg-message "'#include '" "" { target *-*-* } .-1 } strncat(dest, "test", 3); // { dg-error "was not declared" } diff --git a/gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c b/gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c new file mode 100644 index 00000000000..4762e2ddbbd --- /dev/null +++ b/gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c @@ -0,0 +1,8 @@ +/* { dg-options "-Wimplicit-function-declaration" } */ + +/* Missing . */ +void test_string_h (void) +{ + strerror (0); /* { dg-error "implicit declaration of function 'strerror'" } */ + /* { dg-message "'strerror' is defined in header ''" "" { target *-*-* } .-1 } */ +}