From patchwork Fri Dec 17 22:59:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1570397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Rz7wodhm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JG4F25Zpjz9sCD for ; Sat, 18 Dec 2021 09:59:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E6EE3858037 for ; Fri, 17 Dec 2021 22:59:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E6EE3858037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639781988; bh=NSIqv4MaVK6UH7y48Xga97ghyE7kLdkEppWqfl0ltOA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Rz7wodhm0Fbh/1zt6v/OQdHYzOLtez7MT2Sbcu6zfj8EgAg/69pZAvbkibb8Uul23 NS/5z0DwRRv+VloXHiaAMEVn2/r+Cctnb+4IeuspvmsuHBS+Mquqpcvj/9PC2wyaet n1I8ihpUwPV5QxXYVXr0QOYDAqv8chXYNjoum4/8= 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 A8D803858016 for ; Fri, 17 Dec 2021 22:59:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A8D803858016 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-356-wagpktBcOkywTlfTyuoRCg-1; Fri, 17 Dec 2021 17:59:09 -0500 X-MC-Unique: wagpktBcOkywTlfTyuoRCg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80FDC8042CC for ; Fri, 17 Dec 2021 22:59:08 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.9.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id 614065BE28; Fri, 17 Dec 2021 22:59:06 +0000 (UTC) To: GCC Patches Subject: [PATCH] c-family: Have -Wformat-diag accept "decl-specifier" [PR103758] Date: Fri, 17 Dec 2021 17:59:02 -0500 Message-Id: <20211217225902.499568-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.2 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Cc: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" I'm tired of seeing cp/parser.c:15923:55: warning: misspelled term 'decl' in format; use 'declaration' instead [-Wformat-diag] cp/parser.c:15925:57: warning: misspelled term 'decl' in format; use 'declaration' instead [-Wformat-diag] every time I compile cp/parser.c, which happens...a lot. I'd like my compilation to be free of warnings, otherwise I'm going to miss some important ones. "decl-specifiers" is a C++ grammar term; it is not actual code, so should not be wrapped with %< %>. I hope we can accept it as an exception in check_tokens. It was surrounded by %< %> in cp_parser_decl_specifier_seq, so fix that. In passing, fix a misspelling in missspellings. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? In fact, I think I'd like to backport to 11 too, so that eventually even my system compiler stops warning about this. PR c++/103758 gcc/c-family/ChangeLog: * c-format.c (check_tokens): Accept "decl-specifier*". gcc/cp/ChangeLog: * parser.c (cp_parser_decl_specifier_seq): Replace % with %qD. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-condition.C: Adjust dg-error. --- gcc/c-family/c-format.c | 10 +++++++++- gcc/cp/parser.c | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-condition.C | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) base-commit: d7ca2a79b82c6500ead6ab983d14c609e2124eee diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 617fb5ea626..e1b1d6ba31e 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -3194,7 +3194,7 @@ check_tokens (const token_t *tokens, unsigned ntoks, wlen, format_chars); else { - /* Diagnose some common missspellings. */ + /* Diagnose some common misspellings. */ for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i) { unsigned badwlen = strspn (badwords[i].name, " -"); @@ -3215,6 +3215,14 @@ check_tokens (const token_t *tokens, unsigned ntoks, plural = "s"; } + /* As an exception, don't warn about "decl-specifier*" since + it's a C++ grammar production. */ + { + const size_t l = strlen ("decl-specifier"); + if (!strncmp (format_chars, "decl-specifier", l)) + return format_chars + l - 1; + } + format_warning_substr (format_string_loc, format_string_cst, fmtchrpos, fmtchrpos + badwords[i].len, opt, diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 44eed7ea638..3b33ae0cc21 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15820,7 +15820,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser, if (found_decl_spec && (flags & CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR) && token->keyword != RID_CONSTEXPR) - error ("% invalid in condition"); + error ("%qD invalid in condition", ridpointers[token->keyword]); if (found_decl_spec && (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-condition.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-condition.C index 733d494c4d7..e81acba68ae 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-condition.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-condition.C @@ -5,5 +5,5 @@ constexpr int something() { return 3; } int main() { if (constexpr long v = something()) {} - if (static long v = something()) { } // { dg-error "'decl-specifier' invalid" } + if (static long v = something()) { } // { dg-error "'static' invalid" } }