public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix build error in gdbsupport/thread-pool.h
@ 2022-04-13 10:47 Tiezhu Yang
  2022-04-13 14:57 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Tiezhu Yang @ 2022-04-13 10:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Use different variable to fix the following build errors:

  CXX      thread-pool.o
In file included from /home/loongson/gdb.git/gdbsupport/thread-pool.cc:21:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<void> gdb::thread_pool::post_task(std::function<void()>&&)’:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:69:44: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
     std::packaged_task<void ()> task (std::move (func));
                                            ^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
   typedef std::packaged_task<void ()> task;
                                       ^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<_Res> gdb::thread_pool::post_task(std::function<T()>&&)’:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:80:41: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
     std::packaged_task<T ()> task (std::move (func));
                                         ^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
   typedef std::packaged_task<void ()> task;
                                       ^~~~

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 gdbsupport/thread-pool.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdbsupport/thread-pool.h b/gdbsupport/thread-pool.h
index 3243346..74eb8d6 100644
--- a/gdbsupport/thread-pool.h
+++ b/gdbsupport/thread-pool.h
@@ -66,9 +66,9 @@ class thread_pool
      be used to wait for the result.  */
   std::future<void> post_task (std::function<void ()> &&func)
   {
-    std::packaged_task<void ()> task (std::move (func));
-    std::future<void> result = task.get_future ();
-    do_post_task (std::packaged_task<void ()> (std::move (task)));
+    std::packaged_task<void ()> task1 (std::move (func));
+    std::future<void> result = task1.get_future ();
+    do_post_task (std::packaged_task<void ()> (std::move (task1)));
     return result;
   }
 
@@ -77,9 +77,9 @@ class thread_pool
   template<typename T>
   std::future<T> post_task (std::function<T ()> &&func)
   {
-    std::packaged_task<T ()> task (std::move (func));
-    std::future<T> result = task.get_future ();
-    do_post_task (std::packaged_task<void ()> (std::move (task)));
+    std::packaged_task<T ()> task2 (std::move (func));
+    std::future<T> result = task2.get_future ();
+    do_post_task (std::packaged_task<void ()> (std::move (task2)));
     return result;
   }
 
-- 
2.1.0


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

* Re: [PATCH] gdb: fix build error in gdbsupport/thread-pool.h
  2022-04-13 10:47 [PATCH] gdb: fix build error in gdbsupport/thread-pool.h Tiezhu Yang
@ 2022-04-13 14:57 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2022-04-13 14:57 UTC (permalink / raw)
  To: Tiezhu Yang, gdb-patches; +Cc: Tom Tromey

On 2022-04-13 06:47, Tiezhu Yang wrote:
> Use different variable to fix the following build errors:
>
>   CXX      thread-pool.o
> In file included from /home/loongson/gdb.git/gdbsupport/thread-pool.cc:21:
> /home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<void> gdb::thread_pool::post_task(std::function<void()>&&)’:
> /home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:69:44: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
>      std::packaged_task<void ()> task (std::move (func));
>                                             ^~~~
> /home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
>    typedef std::packaged_task<void ()> task;
>                                        ^~~~
> /home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<_Res> gdb::thread_pool::post_task(std::function<T()>&&)’:
> /home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:80:41: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
>      std::packaged_task<T ()> task (std::move (func));
>                                          ^~~~
> /home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
>    typedef std::packaged_task<void ()> task;
>                                        ^~~~
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Can you please state in the commit message the compiler and compiler
version that gives you this?

> ---
>  gdbsupport/thread-pool.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/gdbsupport/thread-pool.h b/gdbsupport/thread-pool.h
> index 3243346..74eb8d6 100644
> --- a/gdbsupport/thread-pool.h
> +++ b/gdbsupport/thread-pool.h
> @@ -66,9 +66,9 @@ class thread_pool
>       be used to wait for the result.  */
>    std::future<void> post_task (std::function<void ()> &&func)
>    {
> -    std::packaged_task<void ()> task (std::move (func));
> -    std::future<void> result = task.get_future ();
> -    do_post_task (std::packaged_task<void ()> (std::move (task)));
> +    std::packaged_task<void ()> task1 (std::move (func));
> +    std::future<void> result = task1.get_future ();
> +    do_post_task (std::packaged_task<void ()> (std::move (task1)));
>      return result;
>    }
>
> @@ -77,9 +77,9 @@ class thread_pool
>    template<typename T>
>    std::future<T> post_task (std::function<T ()> &&func)
>    {
> -    std::packaged_task<T ()> task (std::move (func));
> -    std::future<T> result = task.get_future ();
> -    do_post_task (std::packaged_task<void ()> (std::move (task)));
> +    std::packaged_task<T ()> task2 (std::move (func));
> +    std::future<T> result = task2.get_future ();
> +    do_post_task (std::packaged_task<void ()> (std::move (task2)));
>      return result;
>    }

I'd suggest fixing this by renaming the typedef to task_t instead.

Also, the typedef appears to only be used at a single place.  Since we
have it, we might as well use it everywhere instead of using
`std::packaged_task<void ()>`.  Or, we can remove it if it's not useful.

Simon

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

end of thread, other threads:[~2022-04-13 14:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 10:47 [PATCH] gdb: fix build error in gdbsupport/thread-pool.h Tiezhu Yang
2022-04-13 14:57 ` Simon Marchi

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