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

GetEditWnd()関数のNULLチェック削除 #2008

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gorogoro123
Copy link
Contributor

PR対象

  • アプリ(サクラエディタ本体)

カテゴリ

  • 削除

PR の背景

GetEditWnd()関数で、 CEditWnd::getInstance() の戻り値のNULLチェックを行っているが不要。

仕様・動作説明

  1. CEditWnd::getInstance() の戻り値のNULLチェックを削除します。
  2. inline関数にします。

PR の影響範囲

影響なし。

テスト内容

TSingleton クラスの getInstance() に下記を追加して build エラーになることを確認する。
static_assert(nullptr == &instance);

関連 issue, PR

#1744

参考資料

https://cpprefjp.github.io/lang/cpp11/static_initialization_thread_safely.html

@AppVeyorBot
Copy link

@berryzplus
Copy link
Contributor

berryzplus commented Mar 1, 2025

修正に反対します。

CEditWndがシングルトンなのが「誤り」だと思っています。

一般に、シングルトンは状態を持ってはなりません。
状態を持つクラスのシングルトン化は避けるのが普通です。

CEditWndはサクラエディタのメインウインドウなので状態を持っています。
状態を排除する変更は現実的に不可能です。

なので、方向的には「nullチェックを外す」ではなく「TSingletonの継承を外す」で検討しています。

GetEditWnd()関数はフリー関数であるため、いかなるコンテキストからも呼出できるようにしておくべきです。
コントロールプロセスでは CEditWnd のインスタンスを作成しませんが、フリー関数として残す以上は コントロールプロセスからも呼べるようにしておくのが理想と思っています。

nullチェック後の例外スローの仕方がおかしいのは別件になります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants