-
Notifications
You must be signed in to change notification settings - Fork 163
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
CCommandLine::GetFileNumの戻り値をintにキャストする #1563
CCommandLine::GetFileNumの戻り値をintにキャストする #1563
Conversation
sakura_core/_main/CCommandLine.h
Outdated
@@ -84,7 +84,7 @@ class CCommandLine : public TSingleton<CCommandLine> { | |||
tagSIZE GetWindowSize() const noexcept { return { m_fi.m_nWindowSizeX, m_fi.m_nWindowSizeY }; } | |||
tagPOINT GetWindowOrigin() const noexcept { return { m_fi.m_nWindowOriginX, m_fi.m_nWindowOriginY }; } | |||
LPCWSTR GetOpenFile() const noexcept { return m_fi.m_szPath; } | |||
int GetFileNum(void) const noexcept { return m_vFiles.size(); } | |||
int GetFileNum(void) const noexcept { return int(m_vFiles.size()); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast を使わず、あえて function style でキャストする意図が汲めませんでした。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar的には Major Code Smell だそうです。
https://rules.sonarsource.com/cpp/RSPEC-871
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar的には Major Code Smell だそうです。
https://rules.sonarsource.com/cpp/RSPEC-871
初回の修正で検出されなかったのが謎なんですよね。
これまでやった対応からすると [[nodiscard]]
を付けないと怒られそうな気配があるんですけど、それも現段階では検出されていないような。
マージ後のscanで修正部分以外もチェックしたら新たに警告が出るのかもしれないので、そのあたりは出たとこ勝負でいこうと思っています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
妥当だと思います。
✅ Build sakura 1.0.3499 completed (commit a4c295421f by @berryzplus) |
Kudos, SonarCloud Quality Gate passed! |
✅ Build sakura 1.0.3501 completed (commit 647fb162a3 by @berryzplus) |
戻り値の型を本来は |
ええ、x64対応的には しかし、それは #524 でやろうとしてた感じの大規模修正になります。 戻り値を
INT_MAXの値は約20億で、サクラエディタが同時に開けるファイル数は50個くらい(設計上は100くらい)です。 なので、値域を拡大する意味はないように思います。 |
レビューありがとうございます。マージしちゃいます。 |
PR の目的
カテゴリ
PR の背景
#1541 で x64 対応ブームが始まったので対応してみます。
PR のメリット
x64 ビルドの警告が 13個ほど減ります。
PR のデメリット (トレードオフとかあれば)
とくにありません。
仕様・動作説明
変更対象は、コマンドラインから指定した2個目以降のファイル名を格納したvectorのサイズを返す関数です。
std::vector::size()はsize_tの値を返しますが、関数の戻り型定義がintであるため、
暗黙の縮小変換となってコンパイラが警告を吐いています。
PR の影響範囲
実害はありません。
x64ビルドのメリットとして「コマンドラインに20億個以上のファイル名を指定できる」を売りにできる可能性を潰す修正になります。
テスト内容
すでに作成している単体テストがカバーする範囲の修正であるため、追加のテストは不要と考えています。
関連 issue, PR
#1541
参考資料