public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Enze Li <enze.li@hotmail.com>
To: Tsukasa OI <research_trasio@irq.a4lg.com>
Cc: Pedro Alves <pedro@palves.net>,
	 Joel Brobecker <brobecker@adacore.com>,
	Enze Li <lienze@sourceware.org>,
	 gdb-patches@sourceware.org, binutils@sourceware.org
Subject: Re: [PATCH v2 3/4] gdb/unittests: PR28413, suppress warnings generated by Gnulib
Date: Tue, 18 Oct 2022 21:44:32 +0800	[thread overview]
Message-ID: <OS3P286MB21524D2170537CBC3F7BF86FF0289@OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <667cafec3594a5eb180aee68f8c3adf1531addd3.1663835104.git.research_trasio@irq.a4lg.com> (Tsukasa OI's message of "Thu, 22 Sep 2022 08:25:46 +0000")

Hi Tsukasa,

Thanks for doing this.  I tested this patch on macOS and found one nit.
Please see below.

On Thu, Sep 22 2022 at 08:25:46 AM +0000, Tsukasa OI wrote:

> Gnulib generates a warning if the system version of certain functions
> are used (to redirect the developer to use Gnulib version).  It caused a
> compiler error when...
>
> -   Compiled with Clang
> -   -Werror is specified (by default)
> -   C++ standard used by Clang is before C++17 (by default as of 15.0.0)
>     when this unit test is activated.
>
> This issue is raised as PR28413.
>
> However, previous proposal to fix this issue (a "fix" to Gnulib):
> <https://lists.gnu.org/archive/html/bug-gnulib/2021-10/msg00003.html>
> was rejected because it ruins the intent of Gnulib warnings.
>
> So, we need a Binutils/GDB-side solution.
>
> This commit tries to deal with this issue on the GDB side.  We have
> "include/diagnostics.h" to disable certain warnings only when necessary.
>
> This commit suppresses the Gnulib warnings by adding
> DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS before including "defs.h".
>
> gdb/ChangeLog:
>
> 	pr 28413
> 	* unittests/string_view-selftests.c: Suppress Gnulib-generated
> 	warnings when "defs.h" is included.
> ---
>  gdb/unittests/string_view-selftests.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/gdb/unittests/string_view-selftests.c b/gdb/unittests/string_view-selftests.c
> index 2d7261d18d3..c1f7799d94c 100644
> --- a/gdb/unittests/string_view-selftests.c
> +++ b/gdb/unittests/string_view-selftests.c
> @@ -23,7 +23,12 @@
>  
>  #define GNULIB_NAMESPACE gnulib
>  
> +#include "diagnostics.h"
> +
> +DIAGNOSTIC_PUSH
> +DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
>  #include "defs.h"
> +DIAGNOSTIC_POP
>  #include "gdbsupport/selftest.h"
>  #include "gdbsupport/gdb_string_view.h"

With your patch applied on macOS 15.10.7, it still says,

==========================================================================================
  CXX    unittests/string_view-selftests.o
In file included from unittests/string_view-selftests.c:39:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/fstream:579:17: error: The symbol
      ::fdopen refers to the system function. Use gnulib::fdopen instead.
      [-Werror,-Wuser-defined-warnings]
      __file_ = fdopen(__fd, __mdstr);
                ^
./../gnulib/import/stdio.h:826:1: note: from 'diagnose_if' attribute on 'fdopen':
_GL_CXXALIASWARN (fdopen);
^~~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:461:4: note: expanded from macro '_GL_CXXALIASWARN'
   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:463:4: note: expanded from macro '_GL_CXXALIASWARN_1'
   _GL_CXXALIASWARN_2 (func, namespace)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:468:5: note: expanded from macro '_GL_CXXALIASWARN_2'
    _GL_WARN_ON_USE (func, \
    ^~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:632:19: note: expanded from macro '_GL_WARN_ON_USE'
  __attribute__ ((__diagnose_if__ (1, message, "warning")))
                  ^                ~
1 error generated.
make[2]: *** [unittests/string_view-selftests.o] Error 1
==========================================================================================

I think this can be solved by just adding
DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS before including <fstream>
according to your method.

WDYT?
==========================================================================================
diff --git a/gdb/unittests/string_view-selftests.c b/gdb/unittests/string_view-selftests.c
index 2d7261d18d3..b779b9b765a 100644
--- a/gdb/unittests/string_view-selftests.c
+++ b/gdb/unittests/string_view-selftests.c
@@ -23,7 +23,12 @@

 #define GNULIB_NAMESPACE gnulib

+#include "diagnostics.h"
+
+DIAGNOSTIC_PUSH
+DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
 #include "defs.h"
+DIAGNOSTIC_POP
 #include "gdbsupport/selftest.h"
 #include "gdbsupport/gdb_string_view.h"

@@ -31,7 +36,10 @@
    included test files are wrapped in a namespace.  */
 #include <string>
 #include <sstream>
+DIAGNOSTIC_PUSH
+DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
 #include <fstream>
+DIAGNOSTIC_POP
 #include <iostream>

 /* libstdc++'s testsuite uses VERIFY.  */
==========================================================================================

Other than that, looks good to me.

Reviewed-by: Enze Li <enze.li@hotmail.com>

Thanks,
Enze

  reply	other threads:[~2022-10-18 13:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15  3:10 [PATCH 0/4] gdb: (includes PR28413), Suppress some general warnings if built with Clang Tsukasa OI
2022-09-15  3:10 ` [PATCH 1/4] include: Add macro to ignore -Wuser-defined-warnings Tsukasa OI
2022-09-20 16:36   ` Nick Clifton
2022-09-22 13:02     ` Enze Li
2022-09-15  3:10 ` [PATCH 2/4] include: Add macro to ignore -Wunused-but-set-variable Tsukasa OI
2022-09-15  3:10 ` [PATCH 3/4] gdb/unittests: PR28413, suppress warnings generated by Gnulib Tsukasa OI
2022-09-15  3:10 ` [PATCH 4/4] gdb: Suppress "unused" variable warning on Clang Tsukasa OI
2022-09-22  8:25 ` [PATCH v2 0/4] gdb: (includes PR28413), Suppress some general warnings if built with Clang Tsukasa OI
2022-09-22  8:25   ` [PATCH v2 1/4] include: Add macro to ignore -Wuser-defined-warnings Tsukasa OI
2022-09-22 11:26     ` Nick Clifton
2022-09-22  8:25   ` [PATCH v2 2/4] include: Add macro to ignore -Wunused-but-set-variable Tsukasa OI
2022-09-22 11:27     ` Nick Clifton
2022-09-22  8:25   ` [PATCH v2 3/4] gdb/unittests: PR28413, suppress warnings generated by Gnulib Tsukasa OI
2022-10-18 13:44     ` Enze Li [this message]
2022-10-18 16:14       ` Tsukasa OI
2022-09-22  8:25   ` [PATCH v2 4/4] gdb: Suppress "unused" variable warning on Clang Tsukasa OI
2022-10-12 17:36     ` Simon Marchi
2022-10-16 13:37       ` Tsukasa OI
2022-10-17 12:35         ` Simon Marchi
2022-10-18 17:11   ` [PATCH v3] gdb/unittests: PR28413, suppress warnings generated by Gnulib Tsukasa OI
2022-11-14 14:02     ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OS3P286MB21524D2170537CBC3F7BF86FF0289@OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM \
    --to=enze.li@hotmail.com \
    --cc=binutils@sourceware.org \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lienze@sourceware.org \
    --cc=pedro@palves.net \
    --cc=research_trasio@irq.a4lg.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).