From patchwork Mon Feb 26 06:27:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oskari Pirhonen X-Patchwork-Id: 206272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1898075dyb; Sun, 25 Feb 2024 22:28:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsKQeV7Sd9CDHPqs2w7X0keJm1ViyjiL7NnesLC5wD6gVbBkqS+J/9HaVWVbJJiM4akNKpDdLTCN+YJ281pqC4zy9/MA== X-Google-Smtp-Source: AGHT+IFw40WVWjrRimZrySQCKYgPF8JbZvJj6xT5ztgEIrSx1plZ4d/1k5hPYR66wQcFoxzQ741K X-Received: by 2002:a05:6214:20a8:b0:68f:517d:282b with SMTP id 8-20020a05621420a800b0068f517d282bmr8021223qvd.14.1708928906767; Sun, 25 Feb 2024 22:28:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708928906; cv=pass; d=google.com; s=arc-20160816; b=FmnbJ0H02AgTlgHNO+dF5LG8I5vsDLdUruQaIibIe8WlSXKY4grlqQKvF5mgV2Ym8t PvL6sYDPtZK7kmfKTRjT7CAwctPzXUmDJ0+6CCMvSWftxxfoml4VIylGpojOAHD6CtfS rJ5qmlIBs5j3zAhrhEpmvr6ysoMhfAiXLUgXf3dUGiUwleH8ky+SBAF6rhpvsVBLqyHR 4VaGPo2upt4g8H784d8VA7huLuCgnsIgF32d4nKxLxtFS++siG0TqBDl0+95sf2zsoLn JbZrOR3blBYbB0SoE/YmheYN+m/eNfOYIUR0WfuI3pjqPFHg/0XU0dAcVN0WpPu48+RY f4/g== 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=vRXgy4hGTuAzpYV8OXIgX2I89wfp3/7oVfcyCYxc/AY=; fh=DY76WWugxFSSEiow8Voo+cMAhaQ2VIY1w+QHK6Ta6KU=; b=StDbFYYT9W9ji+gcFtxRZHR5IXpldNh3/U4kp2IJPfbXwOsGG0tSk9LTW4Agk+4yl0 i3GonpC43mG56A8EGt+MHwLRhJRvEvqeB8e+CVxU9eVoudXTXHBsPxK+G8+jv6XLst1K 7tNVtEAdL9QNByNFDDQXPImBJSGVvLzLExsw5+E8RwSEQr0SGqWETE+LehmO0aQjNnW5 vhHqu0KVffdVgGTBiyoOsjPLERteR+Vv45Y1bEm6K84Ngp7wurUyJwhq1uvt2CKz5X/c 1D03SL1dI4rxk9Sf9L6EcJ2VW3KS17+4thos0nXihvIoGHDy6h6PQqdrib4Y+UrQS6MV T8QA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jPfR9403; 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 jf6-20020a0562142a4600b0068d185e9c25si4443140qvb.532.2024.02.25.22.28.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 22:28:26 -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=jPfR9403; 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 767263858404 for ; Mon, 26 Feb 2024 06:28:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 30BA03858D3C for ; Mon, 26 Feb 2024 06:27:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30BA03858D3C 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 30BA03858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::530 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708928857; cv=none; b=O67msh86KGfbVy6qmB7TlBKlwvQTd7CWEbuV8T1TV2fKh7mk8W2LznslXq7urzgX+UFaC15OcRZl5wlWsU/yeCNh5MNThlCvKycavzDaREhD7xklLsRbogGqF+Hj2QJ7d17bOACd+AwAMCZ4Ae0qey4z7qn4lDtr2yL2doevHMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708928857; c=relaxed/simple; bh=8OinRbtzo9kSHNzpp2724pzEHZOikj/sCDFPXvdFPXs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=kiyr4iYk9/yZPBokORmpDhjcFnL+ztKpz/muPgVe54dr1/3DcxhilrkqA6JY5DDWnk8sAWMxIdm+VRw+4W5FZaf73RhcdTz0fhNPxJ8328lHlXrHCNLPzAdxziHK30IJ4EjFisNw3Zc7jBMs31sC8J9Jjs0OhD405CmBHamHMJA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-565d1656c12so1549452a12.1 for ; Sun, 25 Feb 2024 22:27:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708928853; x=1709533653; 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=vRXgy4hGTuAzpYV8OXIgX2I89wfp3/7oVfcyCYxc/AY=; b=jPfR9403ioq3GJbn2e8msQnkxhFOMR7k7o87nt+tLScH/gKMi6hCL5QpU0lblXZaGX iC7IdYZIyCCBNBpkeJ3Q/lrVu7HwerYBOdkUHFclKGb0cnu5GzBb1te89ogZvB0OncjX C6a7//JgrC9jnqxqgK44i6Noc/8O5dIQy5kSwPh3RdjAffzBj5dEDjUNLuNkTBudkocE lCL9cKg/mJWJlehSeQkgrYF+zwJbcIJbunP5dYxQ9Fko/6coBdIIwwY2MW3go8YNO0d3 g5c0F9MBFKc8KXa6/P2KurD604DpYOjdZE+HSOLGd4aLZolRvARuDJ1fDCoBI4fKPgha L9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708928853; x=1709533653; 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=vRXgy4hGTuAzpYV8OXIgX2I89wfp3/7oVfcyCYxc/AY=; b=nUTbtVssZnt7WqTPOvXkRoawTT1464+Tx1CyURuUR7JWapxOL0SOLgDhp7SP0ZvUqR XJuyjnpdVPzh8whokNRyaPAzHjSk6xg7c8vhinpt+C9m0l8HmXUNpgmrq1nmxdKHt8UQ jioYf+3CkPSm8X93wpt93BhMDOSYkd7B7I7xlCQnzXikazB01Kxnh8aRxHfrMUU0lT1F VwtZ3Luj26ehMNznKhPimUx2yS2+HVxvJXVvfmkxia27q6GH2qWuOWYZzfq3m6b6Ty6B gmF8BaX89QyzErTlp79lUHvl3JLjOz7dJzYTaZxxgxnJFEwIS9nZbbgVSWdMoI3p0JBN c6/A== X-Gm-Message-State: AOJu0YxvQ0cVHuDq8Cy9LV8GaAkREfTMjuRuiLXYyAYv+9Z9yBukoRTj JJlBlvPZLm/8OQF1jFTW30C7/3WBqDhV5n3X5WObcidxfJT9YxVug7h/IgZr X-Received: by 2002:aa7:d4d4:0:b0:565:9f59:b3b6 with SMTP id t20-20020aa7d4d4000000b005659f59b3b6mr4783396edr.3.1708928853127; Sun, 25 Feb 2024 22:27:33 -0800 (PST) Received: from dj3ntoo (30.sub-97-147-14.myvzw.com. [97.147.14.30]) by smtp.gmail.com with ESMTPSA id h10-20020aa7c94a000000b00565dd45b53esm1011821edt.39.2024.02.25.22.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 22:27:32 -0800 (PST) Date: Mon, 26 Feb 2024 00:27:27 -0600 From: Oskari Pirhonen To: gcc-patches@gcc.gnu.org Cc: dodji@redhat.com, dmalcolm@redhat.com Subject: [RESEND PATCH] 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: 1791941837202173766 X-GMAIL-MSGID: 1791941837202173766 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 --- 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..61c17f350cb --- /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-warning "implicit declaration of function 'strerror'" } */ + /* { dg-message "'strerror' is defined in header ''" "" { target *-*-* } .-1 } */ +}