NULLマクロの再定義をやめる#2104
Conversation
|
NULL を使い続ける個所と nullptr を使う個所の違いは何ですか? |
数値に対してはNULLのままでよいです。 |
There was a problem hiding this comment.
Pull Request Overview
This PR stops redefining the NULL macro as nullptr, reverting to the standard definition and updating code to use nullptr explicitly for pointer operations.
- Removed custom
#define NULL nullptrinStdAfx.h - Replaced
NULLwithnullptrin pointer assignments/comparisons - Updated unit tests to assign and compare using
nullptr
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/unittests/test-cnative.cpp | Removed local NULL macro hack and updated pointer tests to nullptr |
| sakura_core/env/CShareData.cpp | Swapped all NULL pointer initializations and checks to nullptr |
| sakura_core/StdAfx.h | Deleted custom redefinition of NULL |
Comments suppressed due to low confidence (2)
tests/unittests/test-cnative.cpp:255
- [nitpick] Replace
NULLwithnullptrin the assertion to keep pointer comparisons consistent after removing theNULLmacro redefinition.
EXPECT_EQ(NULL, value.GetStringPtr());
tests/unittests/test-cnative.cpp:267
- [nitpick] Use
nullptrinstead ofNULLhere for consistency in pointer assertions.
ASSERT_EQ(NULL, value.GetStringPtr());
|
|
||
| // 未確保状態からの書式化をテストする | ||
| value = NULL; //テスト前の初期値(未確保 | ||
| value = nullptr; //テスト前の初期値(未確保 |
There was a problem hiding this comment.
[nitpick] The comment is missing a closing parenthesis—consider changing to // テスト前の初期値 (未確保).
There was a problem hiding this comment.
コメントに対する指摘なのでスルーします。
(修正しても振る舞いに影響がないため。)
| { | ||
| std::wstring longText( 2048, L'=' ); | ||
| value = NULL; //テスト前の初期値(未確保 | ||
| value = nullptr; //テスト前の初期値(未確保 |
There was a problem hiding this comment.
[nitpick] Add the missing closing parenthesis in the comment: // テスト前の初期値 (未確保).
| value = nullptr; //テスト前の初期値(未確保 | |
| value = nullptr; //テスト前の初期値(未確保) |
There was a problem hiding this comment.
コメントに対する指摘なのでスルーします。
(修正しても振る舞いに影響がないため。)
|
#2110 のマージによりコンフリクト発生していたので master をマージしました。 |
|
SonarQubeのNew Issue 1件は元からの問題なのでスルーしてください。 |
|



PR対象
カテゴリ
PR の背景
このプロジェクトでは NULLマクロを nullptr に再定義することで、
ポインタに NULL を代入するコードの警告を抑制しています。
しかし、NULLが本来の目的、無効値として使われる状況では数値型引数に NULL を指定したりするので NULL を nullptr に置換する対応では都合がよくありません。
いまのところ、 gdiplus.h をインクルードするとコンパイルエラーになることが分かっています。
仕様・動作説明
NULLの再定義をやめます。
PR の影響範囲
プログラム全域に影響します。
数値型引数に NULL を指定できるようになります。
ポインタ型引数に NULL を指定すると警告が出るようになります。
数値型変数に NULL を代入できるようになります。
ポインタ型変数に NULL を代入するコードで警告が出るようになります。
機能上の実害はないと考えられます。
テスト内容
ビルドできること
NULLの再定義をやめたことで発生する大量の警告は一旦放置します。
関連 issue, PR
NULLマクロの再定義を導入したPull-Requestです。
このPull Requestの変更を含んでいます。
「LCIDToLocaleNameの第4引数にNULLを指定するために必要な変更」の位置づけです。
LCIDToLocaleNameの第4引数にはNULLを指定することになっていますが数値型引数なので nullptr を指定できません。
参考資料