From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101852 invoked by alias); 13 Oct 2019 23:54:32 -0000 Mailing-List: contact gdb-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: gdb-cvs-owner@sourceware.org List-Subscribe: Sender: gdb-cvs-owner@sourceware.org Received: (qmail 101812 invoked by uid 10037); 13 Oct 2019 23:54:32 -0000 Date: Sun, 13 Oct 2019 23:54:00 -0000 Message-ID: <20191013235432.101810.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: Silence -Wformat-nonliteral warning with clang X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: d039f01465b37026e538b06ff792aadc4b19bf24 X-Git-Newrev: 284782de0750d6c0a24f2c8fd712b2954423e849 X-SW-Source: 2019-10/txt/msg00114.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=284782de0750d6c0a24f2c8fd712b2954423e849 commit 284782de0750d6c0a24f2c8fd712b2954423e849 Author: Simon Marchi Date: Fri Oct 11 15:36:49 2019 -0400 gdb: Silence -Wformat-nonliteral warning with clang We get this warning when building with clang: CXX ui-out.o /home/smarchi/src/binutils-gdb/gdb/ui-out.c:590:22: error: format string is not a string literal [-Werror,-Wformat-nonliteral] do_message (style, format, args); ^~~~~~ This can be considered a legitimate warning, as call_do_message's format parameter is not marked as a format string. Therefore, we should normally mark the call_do_message method with the `format` attribute. However, doing so just moves (and multiplies) the problem, as all the uses of call_do_message in the vmessage method now warn. If we wanted to continue on that path, we should silence the warning for each of them, as a way of telling the compiler "it's ok, we know what we are doing". But since call_do_message is really just vmessage's little helper, it's simpler to just silence the warning at that single point. gdb/ChangeLog: * ui-out.c (ui_out::call_do_message): Silence -Wformat-nonliteral warning. Change-Id: I58ad41793448f38835c5d6ba7b9e5c4dd8df260f Diff: --- gdb/ChangeLog | 5 +++++ gdb/ui-out.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5c3b45b..bcedf02 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-10-13 Simon Marchi + + * ui-out.c (ui_out::call_do_message): Silence + -Wformat-nonliteral warning. + 2019-10-12 Simon Marchi * breakpoint.c: Remove some includes: continuations.h, skip.h, diff --git a/gdb/ui-out.c b/gdb/ui-out.c index a64c794..6b0b5ac 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -26,6 +26,7 @@ #include "ui-out.h" #include "gdbsupport/format.h" #include "cli/cli-style.h" +#include "diagnostics.h" #include #include @@ -587,7 +588,15 @@ ui_out::call_do_message (const ui_file_style &style, const char *format, va_list args; va_start (args, format); + + /* Since call_do_message is only used as a helper of vmessage, silence the + warning here once instead of at all call sites in vmessage, if we were + to put a "format" attribute on call_do_message. */ + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL do_message (style, format, args); + DIAGNOSTIC_POP + va_end (args); }