node-addon-api icon indicating copy to clipboard operation
node-addon-api copied to clipboard

AsyncProgress*Worker does not support compile option -Woverloaded-virtual

Open jerylvaz opened this issue 3 years ago • 3 comments

Due to Execute() method overloaded in AsyncProgressWorker and AsyncProgressQueueWorker, projects using these classes and with -Woverloaded-virtual enabled will fail to compile.

Reproduction Apply the following and run tests.

diff --git a/common.gypi b/common.gypi
index 9be254f..17e78fb 100644
--- a/common.gypi
+++ b/common.gypi
@@ -17,5 +17,5 @@
   ],
   'include_dirs': ["<!(node -p \"require('../').include_dir\")"],
   'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ],
-  'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ]
+  'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter', '-Woverloaded-virtual' ]
 }

Workaround Classes derived from AsyncProgressQueueWorker must add using AsyncWorker::Execute;. Diff for tests:

diff --git a/test/async_progress_queue_worker.cc b/test/async_progress_queue_worker.cc
index eec3f95..c3d4542 100644
--- a/test/async_progress_queue_worker.cc
+++ b/test/async_progress_queue_worker.cc
@@ -16,6 +16,7 @@ struct ProgressData {
 };
 
 class TestWorker : public AsyncProgressQueueWorker<ProgressData> {
+ using AsyncWorker::Execute;
  public:
   static Napi::Value CreateWork(const CallbackInfo& info) {
     int32_t times = info[0].As<Number>().Int32Value();
diff --git a/test/async_progress_worker.cc b/test/async_progress_worker.cc
index 36087e7..f3ffbf5 100644
--- a/test/async_progress_worker.cc
+++ b/test/async_progress_worker.cc
@@ -16,6 +16,7 @@ struct ProgressData {
 };
 
 class TestWorker : public AsyncProgressWorker<ProgressData> {
+ using AsyncWorker::Execute;
  public:
   static void DoWork(const CallbackInfo& info) {
     int32_t times = info[0].As<Number>().Int32Value();
@@ -66,6 +67,7 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
 };
 
 class MalignWorker : public AsyncProgressWorker<ProgressData> {
+ using AsyncWorker::Execute;
  public:
   static void DoWork(const CallbackInfo& info) {
     Function cb = info[0].As<Function>();

jerylvaz avatar Jun 18 '22 18:06 jerylvaz

Hi @jerylvaz,

Thanks for noticing this. Would you like to submit a PR...?

KevinEady avatar Jun 18 '22 19:06 KevinEady

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

github-actions[bot] avatar Sep 17 '22 00:09 github-actions[bot]

Hi @KevinEady, I don't think a fix is possible without breaking the API.

jerylvaz avatar Sep 19 '22 07:09 jerylvaz

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

github-actions[bot] avatar Dec 20 '22 00:12 github-actions[bot]

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

github-actions[bot] avatar Apr 14 '23 00:04 github-actions[bot]