https://github.com/na-trium-144/nullp-checker
nullptr checker for c++ smart pointer
https://github.com/na-trium-144/nullp-checker
cpp11 null-check null-safety
Last synced: 12 months ago
JSON representation
nullptr checker for c++ smart pointer
- Host: GitHub
- URL: https://github.com/na-trium-144/nullp-checker
- Owner: na-trium-144
- Created: 2023-07-31T10:43:33.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-03T14:17:13.000Z (almost 3 years ago)
- Last Synced: 2025-07-01T12:03:05.323Z (12 months ago)
- Topics: cpp11, null-check, null-safety
- Language: C++
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ぬるぽチェッカー
c++のスマートポインタ(や配列)を置き換え、nullptr(や範囲外)にアクセスしたときに変数名とともに例外を投げます
## usage
* STLの各種クラスをnpchkのクラスで置き換えて使います
* `std::shared_ptr` → `npchk::shared_ptr`
* `std::array` → `npchk::array`
* `std::vector` → `npchk::array`
* `std::deque` → `npchk::deque`
* エラーメッセージの表示のために変数名を登録する必要があります
* 変数の定義時に`NPCHK`マクロを使用すると自動で設定できます
* `NPCHK`マクロはnpchkのクラスがネストしていても(例えば`npchk::array,3>`とか)使えます
* 型のテンプレートに`,`を含む場合は型名全体を`( )`で囲う
* マクロ1つで変数8個まで同時に定義できます
* inlineは`inline NPCHK(...);`
* externは普通に宣言し定義時にのみ`NPCHK`を使う
```c++
// std::array var の代わりに
NPCHK((npchk::array), var);
```
* または`var.setName("var");`
* これもnpchkのクラスがネストしている場合は再帰的に設定されます
## example
```c++
#include "npchk.hpp"
#include
#include
struct Hoge {
int val;
Hoge(int val) : val(val) {}
};
NPCHK(npchk::shared_ptr, hoge1, hoge2);
int main() {
hoge1 = std::make_shared(3);
std::cout << hoge1->val << std::endl;
std::cout << hoge2->val << std::endl;
}
```
```
3
terminate called after throwing an instance of 'std::runtime_error'
what(): hoge2 is nullptr
中止 (コアダンプ)
```