From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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== Return-Path: 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 22:39:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5B537D36D4B5F6F4BD7EDA73" X-IsSubscribed: yes X-SW-Source: 2018-10/txt/msg00703.txt.bz2 This is a multi-part message in MIME format. --------------5B537D36D4B5F6F4BD7EDA73 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 662 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 --------------5B537D36D4B5F6F4BD7EDA73 Content-Type: text/x-patch; name="gcc-attr-format-arg.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-attr-format-arg.diff" Content-length: 1924 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 --------------5B537D36D4B5F6F4BD7EDA73--