Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: Silence -Wformat-nonliteral warning with clang
@ 2019-10-11 20:54 Simon Marchi
  2019-10-13 18:17 ` Kevin Buettner
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2019-10-11 20:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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
---
 gdb/ui-out.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index a64c79481cad..6b0b5acd3e13 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 <vector>
 #include <memory>
@@ -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);
 }
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: Silence -Wformat-nonliteral warning with clang
  2019-10-11 20:54 [PATCH] gdb: Silence -Wformat-nonliteral warning with clang Simon Marchi
@ 2019-10-13 18:17 ` Kevin Buettner
  2019-10-14  0:00   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2019-10-13 18:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

On Fri, 11 Oct 2019 16:54:26 -0400
Simon Marchi <simon.marchi@efficios.com> wrote:

> 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.

LGTM.

Kevin


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: Silence -Wformat-nonliteral warning with clang
  2019-10-13 18:17 ` Kevin Buettner
@ 2019-10-14  0:00   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2019-10-14  0:00 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches, Simon Marchi

On 2019-10-13 14:17, Kevin Buettner wrote:
> On Fri, 11 Oct 2019 16:54:26 -0400
> Simon Marchi <simon.marchi@efficios.com> wrote:
> 
>> 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.
> 
> LGTM.
> 
> Kevin

Thanks, I pushed it.

Simon


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-14  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 20:54 [PATCH] gdb: Silence -Wformat-nonliteral warning with clang Simon Marchi
2019-10-13 18:17 ` Kevin Buettner
2019-10-14  0:00   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox