gdb: fix build errors in gdbsupport/thread-pool.h used with old gcc
authorTiezhu Yang <yangtiezhu@loongson.cn>
Thu, 14 Apr 2022 02:37:30 +0000 (10:37 +0800)
committerTiezhu Yang <yangtiezhu@loongson.cn>
Thu, 14 Apr 2022 15:05:00 +0000 (23:05 +0800)
When I build gdb with gcc 8.3, there exist the following build errors,
rename the typedef to task_t to fix them.

  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.cc
gdbsupport/thread-pool.h

index efd8b7997139be1a9721072e53eca613345494b5..464e32fe79e244cde0b12775dabb042f566b24c1 100644 (file)
@@ -171,7 +171,7 @@ thread_pool::thread_function ()
 
   while (true)
     {
-      optional<task> t;
+      optional<task_t> t;
 
       {
        /* We want to hold the lock while examining the task list, but
index 3243346771f9ad2827f3f7c605e3109341123463..5e203fd896c189d5a561f6fdc79e25ce43a05bf7 100644 (file)
@@ -99,13 +99,13 @@ private:
   size_t m_thread_count = 0;
 
   /* A convenience typedef for the type of a task.  */
-  typedef std::packaged_task<void ()> task;
+  typedef std::packaged_task<void ()> task_t;
 
   /* The tasks that have not been processed yet.  An optional is used
      to represent a task.  If the optional is empty, then this means
      that the receiving thread should terminate.  If the optional is
      non-empty, then it is an actual task to evaluate.  */
-  std::queue<optional<task>> m_tasks;
+  std::queue<optional<task_t>> m_tasks;
 
   /* A condition variable and mutex that are used for communication
      between the main thread and the worker threads.  */