From patchwork Thu Oct 11 21:23:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 982742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487399-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="W8C8tAh5"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="P6XlFI3z"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42WP9K5SP0z9s1x for ; Fri, 12 Oct 2018 08:24:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=B0fN9gzaevq+PwzVZ/NEdLK+aDDCOkjSOkQs2fvqVCQXV7YWJQ R/1GCaJS7rDWTs8II4iyyxjQg47jnJAfCLuASEHeIsAS7cYG11qy7wOzQ4bmeMhD 33szM7/iqJ6hj4OgvZ2pdZ1al2MWtcTbVMdrxYfI9lpWTtganpUdagz5s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=zmDg1ObdyAJRFB1Jzhpy1o8OqQ0=; b=W8C8tAh515W7KSr31Rgm OXy/MwwO8eaq7SppESaqx7ymczbDEeiDp3Hdy6NiP6VHqLmHSAZfCjV2H4ic8lb9 rtdAnSIAABhrz2SQd5PE8yL5iF0QvIrl4U8RVw9/j2qJPDNylQ+wfboXiLn5ofFj uD5JUTuwjscgNGOTLEgulYE= Received: (qmail 28106 invoked by alias); 11 Oct 2018 21:23:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 28086 invoked by uid 89); 11 Oct 2018 21:23:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=unmodified X-HELO: mail-qt1-f180.google.com Received: from mail-qt1-f180.google.com (HELO mail-qt1-f180.google.com) (209.85.160.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Oct 2018 21:23:53 +0000 Received: by mail-qt1-f180.google.com with SMTP id u34-v6so11659359qth.3 for ; Thu, 11 Oct 2018 14:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version; bh=dTCfJRQDfs/HK4gJTXDVAwV7pPlbK8Bvjo5FxULzf7c=; b=P6XlFI3zrlx+JPGs97dtDa6Lle9Nk1LrKnbCTcz3zlSaL2ZxBv/0EphPZD64JO8kbr ALXY0q/JLOzP0cskf781MDQ97wzd3EhPsFl/I9xJ+ik1L1do/+YjJp0uNMxPpAc/7dWH ImKr13ybDscq1Th3Q5gUexcv6Rp3tc6V33H5Fs0+nbMB/YDC4/MgIT7ofw7XDUsNXL7d ihAgcY5R2xkC4JZlOjcCmGKXTmfNxIGxg/EgTZPnA9tyIZ+vyDcyzeiFU6td99NG7vvb 532jUlESTuRLbQYTWoTA0TwH+v1SA6UVMcbKrSiDGxXhvc5WOY4s43cAvUVR3kVYHiSK Ox9A== Received: from localhost.localdomain (184-96-225-137.hlrn.qwest.net. [184.96.225.137]) by smtp.gmail.com with ESMTPSA id 128-v6sm13550311qko.7.2018.10.11.14.23.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 14:23:50 -0700 (PDT) To: Joseph Myers , Gcc Patch List From: Martin Sebor Subject: [doc PATCH] using multiple format-arg attributes on a single function (PR 87593) Message-ID: <7d7bacdc-6163-6e3d-72d4-6e05857c82ee@gmail.com> Date: Thu, 11 Oct 2018 15:23:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Attached is a documentation-only patch to clarify the use case of multiple distinct format_arg attributes on a single function. It's far from obvious that the use case makes sense so explicitly mentioning it should help avoid the mistake of assuming that accepting it is due to the lack of better checking in the area (it could also prompt Clang to support the use case -- likely an omission due to its obscurity). However, since it makes less sense to declare the same function multiple times with distinct format_arg attributes, a follow-on improvement would be to issue a warning on such instances. I'll leave the bug open until that's implemented. Martin gcc/ChangeLog: * doc/extend.texi (attribute format_arg): Discuss using multiple attributes on a single function. diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 0d9b99f..6355453 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2698,13 +2699,15 @@ Target Machines}. @item format_arg (@var{string-index}) @cindex @code{format_arg} function attribute @opindex Wformat-nonliteral -The @code{format_arg} attribute specifies that a function takes a format -string for a @code{printf}, @code{scanf}, @code{strftime} or +The @code{format_arg} attribute specifies that a function takes one or +more format strings for a @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style function and modifies it (for example, to translate it into another language), so the result can be passed to a @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style function (with the remaining arguments to the format function the same -as they would have been for the unmodified string). For example, the +as they would have been for the unmodified string). Multiple +@code{format_arg} attributes may be applied to the same function, each +designating a distinct parameter as a format string. For example, the declaration: @smallexample @@ -2724,6 +2727,11 @@ string argument is not constant; this would generate a warning when @option{-Wformat-nonliteral} is used, but the calls could not be checked without the attribute. +In calls to a function declared with more than one @code{format_arg} +attribute, each with a distinct argument value, the corresponding +actual function arguments are checked against all format strings +designated by the attributes. + The parameter @var{string-index} specifies which argument is the format string argument (starting from one). Since non-static C++ methods have an implicit @code{this} argument, the arguments of such methods should