Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArticleBase: Fix calling virtual function from the destructor #284

Conversation

ma8ma
Copy link
Collaborator

@ma8ma ma8ma commented May 16, 2020

ArticleBaseはデストラクタ内で仮想関数unlock_impl()を呼び出していますが、仮想関数はデストラクタ内で派生クラスの関数として呼び出しできないためcppcheckに警告されます。
そのためスコープ解決演算子を使ってクラスを明示します。

cppehckのレポート

src/dbtree/articlebase.h:420:14: warning: Virtual function 'unlock_impl' is called from destructor '~ArticleBase()' at line 120. Dynamic binding is not used. [virtualCallInConstructor]
        void unlock_impl() override;
             ^
src/dbtree/articlebase.cpp:120:5: note: Calling unlock_impl
    unlock_impl();
    ^
src/dbtree/articlebase.h:420:14: note: unlock_impl is a virtual function
        void unlock_impl() override;
             ^

ArticleBaseはデストラクタ内で仮想関数unlock_impl()を呼び出していますが
仮想関数はデストラクタ内で派生クラスの関数として呼び出しできないため
cppcheckに警告されます。そのためスコープ解決演算子を使ってクラスを
明示します。

cppehckのレポート
```
src/dbtree/articlebase.h:420:14: warning: Virtual function 'unlock_impl' is called from destructor '~ArticleBase()' at line 120. Dynamic binding is not used. [virtualCallInConstructor]
        void unlock_impl() override;
             ^
src/dbtree/articlebase.cpp:120:5: note: Calling unlock_impl
    unlock_impl();
    ^
src/dbtree/articlebase.h:420:14: note: unlock_impl is a virtual function
        void unlock_impl() override;
             ^
```
@ma8ma ma8ma added the bug バグの追跡 label May 16, 2020
@ma8ma ma8ma added this to In progress in State of JDim-v0.3.0+ May 16, 2020
@@ -117,7 +117,7 @@ ArticleBase::~ArticleBase()
assert( get_lock() == 0 );

// nodetreeのクリアと情報保存
unlock_impl();
ArticleBase::unlock_impl();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefPtr_lock、Lockableと合わせて参照カウント方式のスマートポインターを実装しています。
標準ライブラリに置き換えられないかそのうち検証したいと思います。

@ma8ma ma8ma merged commit 2071d13 into JDimproved:master May 16, 2020
State of JDim-v0.3.0+ automation moved this from In progress to Done May 16, 2020
@ma8ma ma8ma deleted the articlebase-fix-calling-virtual-function-from-dtor branch May 16, 2020 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug バグの追跡
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant