問題タブ [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.

0 投票する
2 に答える
2108 参照

c++ - なぜclang-tidyはどこにでも[[nodiscard]]を追加することを提案するのですか?

clang-tidyどこにでも追加することを提案している C++ プロジェクトがあり[[nodiscard]]ます。これは良い習慣ですか?私が理解しているのは[[nodiscard]]、戻り値を無視することがプログラムにとって致命的である可能性がある場合にのみ使用する必要があるということです。オブジェクトCarがあり、メンバーがありconst unsigned int m_IDます。ゲッターunsigned int getID()には[[nodiscard]]? clang-tidy そう示唆している。

編集:

もちろん、ゲッターを無視したくありません。しかし
、私のポイントは、何かを返すすべての関数が を持つ必要がある[[nodiscard]]場合、属性[[nodiscard]]はとにかく冗長です。コンパイラは、何かを返すすべての関数を単純にチェックできます。