問題タブ [nodiscard]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - なぜclang-tidyはどこにでも[[nodiscard]]を追加することを提案するのですか?
clang-tidy
どこにでも追加することを提案している C++ プロジェクトがあり[[nodiscard]]
ます。これは良い習慣ですか?私が理解しているのは[[nodiscard]]
、戻り値を無視することがプログラムにとって致命的である可能性がある場合にのみ使用する必要があるということです。オブジェクトCar
があり、メンバーがありconst unsigned int m_ID
ます。ゲッターunsigned int getID()
には[[nodiscard]]
? clang-tidy
そう示唆している。
編集:
もちろん、ゲッターを無視したくありません。しかし
、私のポイントは、何かを返すすべての関数が を持つ必要がある[[nodiscard]]
場合、属性[[nodiscard]]
はとにかく冗長です。コンパイラは、何かを返すすべての関数を単純にチェックできます。