Skip to content

定義された用語の意図しない使用方法を検出するスクリプトを追加 #1348

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

Merged
merged 19 commits into from
Nov 11, 2024

Conversation

faithandbrave
Copy link
Member

@faithandbrave faithandbrave commented Aug 29, 2024

「未定義」の意図しない使用方法を検出してみました。

許可された使用法として以下を設定して見ましたが、「挙動は未定義」と「振る舞いは未定義」は「動作は未定義」に統合してしまっていいかもしれません。

  • 未定義動作
  • 未定義の動作
  • 動作は未定義
  • 挙動は未定義
  • 振る舞いは未定義

仕様を調べながら、個別の問題をどう直すか相談していく必要がありそうです。
このスクリプトでの意図しない「未定義」の使用が0になったらマージします。

site % python3 .github/workflows/script/defined_word_check.py
implementation-status.md: the file includes unintended word use "未定義". Around the word:"| P0137R1: [参照メンバをもつクラスの置き換え](/lang/cpp17/replacement_of_class_objects_containing_reference_members.md) | 参照型メンバや`const`メンバ変数を含むクラスについてこれまで結果は未定義とされていた配置`new`によるオブジェクトの置き換えを条件付きで可能とする | 7 | 6.0 | No | 2017 Update 7 |"
lang/cpp11/lambda_expressions.md: the file includes unintended word use "未定義". Around the word:"  foo()(2); // 未定義の振る舞い"
lang/cpp17.md: the file includes unintended word use "未定義". Around the word:"| [参照メンバをもつクラスの置き換え](cpp17/replacement_of_class_objects_containing_reference_members.md) | 参照型メンバや`const`メンバ変数を含むクラスについてこれまで結果は未定義とされていた配置`new`によるオブジェクトの置き換えを条件付きで可能とする |"
reference/array/array/back.md: the file includes unintended word use "未定義". Around the word:"要素数が0の場合(`N == 0`の場合)、この関数呼び出しの効果は未定義である。"
reference/array/array/front.md: the file includes unintended word use "未定義". Around the word:"要素数が0の場合(`N == 0`の場合)、この関数呼び出しの効果は未定義である。"
reference/atomic/atomic/fetch_add.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic/fetch_sub.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic/op_minus_assign.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic/op_plus_assign.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic_fetch_add.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_add_explicit.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_and.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_and_explicit.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_or.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_or_explicit.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_sub.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_sub_explicit.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_xor.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_fetch_xor_explicit.md: the file includes unintended word use "未定義". Around the word:"符号付き整数型に対しては、2の補数表現による演算が行われ、未定義動作はない。アドレス型に関しては結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない。"
reference/atomic/atomic_ref/fetch_add.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic_ref/fetch_sub.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic_ref/op_minus_assign.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/atomic/atomic_ref/op_plus_assign.md: the file includes unintended word use "未定義". Around the word:"    - 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない"
reference/cstddef/offsetof.md: the file includes unintended word use "未定義". Around the word:"スタンダードレイアウトではないクラス型においての`offsetof`の利用は条件付きのサポートとなる(C++17より以前は未定義)。"
reference/future/shared_future/get.md: the file includes unintended word use "未定義". Around the word:"- `future::get()` : 共有状態に格納されている値への`const`左辺値参照を返す。<br/>備考:共有状態が破壊された後、その参照を介してのアクセスは未定義の振る舞いをする。`shared_future`オブジェクトの寿命よりも長いオブジェクトに参照を保持しないこと。"
reference/ios/basic_ios/op_assign.md: the file includes unintended word use "未定義". Around the word:"- コピー代入演算子は `private` で未定義(C++03 まで)、あるいは、`public` で `delete`(C++11 から)である。  "
reference/ios/basic_ios/op_constructor.md: the file includes unintended word use "未定義". Around the word:"- コピーコンストラクタは `private` で未定義(C++03 まで)、あるいは、`public` で `delete`(C++11 から)である。  "
reference/ios/ios_base/op_assign.md: the file includes unintended word use "未定義". Around the word:"- コピー代入演算子は `private` で未定義(C++03 まで)、あるいは、`public` で `delete`(C++11 から)である。  "
reference/ios/ios_base/op_constructor.md: the file includes unintended word use "未定義". Around the word:"- コピーコンストラクタは `private` で未定義(C++03 まで)、あるいは、`public` で `delete`(C++11 から)である。  "
reference/list/list/merge.md: the file includes unintended word use "未定義". Around the word:"- 移動先と移動元のアロケータが等値でない場合(`get_allocator() != x.get_allocator()`の場合)、この関数呼び出しの効果は未定義である。"
reference/list/list/splice.md: the file includes unintended word use "未定義". Around the word:"- 移動先と移動元のアロケータが等値でない場合(`get_allocator() != x.get_allocator()`の場合)、この関数呼び出しの効果は未定義である。"
reference/new/op_new.md: the file includes unintended word use "未定義". Around the word:"    ただし、記憶域の確保に失敗する可能性もあり、また、成功しても当該ポインタを間接参照した場合の結果は未定義である。"
reference/new/op_new[].md: the file includes unintended word use "未定義". Around the word:"    ただし、記憶域の確保に失敗する可能性もあり、また、成功しても当該ポインタを間接参照した場合の結果は未定義である。"
reference/node_handle/node_handle.md: the file includes unintended word use "未定義". Around the word:"`key_type` を `K`、 `mapped_type` を `T` としたとき、`std::pair<K, T>`または`std::pair<const K, T>`に対するユーザー定義の特殊化が存在する場合、ノードハンドルを用いる操作は未定義である。"
reference/ranges/range_adaptor_closure.md: the file includes unintended word use "未定義". Around the word:"CV修飾を含む`D`を引数とする `|` 演算子を含む式の動作は、プログラム定義の`operator|`関数が選択された場合は未定義である。"
reference/regex/regex_iterator.md: the file includes unintended word use "未定義". Around the word:"シーケンス終端のイテレータに対する [`operator*`](regex_iterator/op_deref.md) 演算子適用は未定義である。その他のイテレータに対する [`operator*`](regex_iterator/op_deref.md) 演算子適用の結果は `const` [`match_results`](match_results.md)`<BidirectionalIterator>&` である。  "
reference/regex/regex_iterator.md: the file includes unintended word use "未定義". Around the word:"同様に、シーケンス終端のイテレータに対する [`operator->`](regex_iterator/op_arrow.md) 演算子適用は未定義である。その他のイテレータに対する [`operator->`](regex_iterator/op_arrow.md) 演算子適用の結果は `const` [`match_results`](match_results.md)`<BidirectionalIterator>*` である。"
reference/regex/regex_token_iterator.md: the file includes unintended word use "未定義". Around the word:"シーケンス終端のイテレータに対する [`operator*`](regex_token_iterator/op_deref.md) 演算子適用は未定義である。その他のイテレータに対する [`operator*`](regex_token_iterator/op_deref.md) 演算子適用の結果は `const` [`sub_match`](sub_match.md)`<BidirectionalIterator>&` である。  "
reference/regex/regex_token_iterator.md: the file includes unintended word use "未定義". Around the word:"同様に、シーケンス終端のイテレータに対する [`operator->`](regex_token_iterator/op_arrow.md) 演算子適用は未定義である。その他のイテレータに対する [`operator->`](regex_token_iterator/op_arrow.md) 演算子適用の結果は `const` [`sub_match`](sub_match.md)`<BidirectionalIterator>*` である。"

@faithandbrave
Copy link
Member Author

「効果は未定義」を「動作は未定義」に修正しました

@faithandbrave
Copy link
Member Author

faithandbrave commented Aug 29, 2024

atomic<T*>のfetch操作の以下の文章について、

「- 結果として未定義アドレスになる場合があるが、それ以外の未定義動作はない」

仕様ではundefinedが使われていました。

Remarks: The result may be an undefined address, but the operations otherwise have no undefined behavior.

これは「未定義アドレス」とするしかないように思いますので、やはり用語定義 (GLOBAL_DEFINED_WORDS.json) から「未定義」を外し、許可された使用方法に「未定義アドレス」を加えることになりそうです。

@akinomyoga
Copy link
Member

「挙動は未定義」と「振る舞いは未定義」は「動作は未定義」に統合してしまっていいかもしれません。

👍 一票。普通の英語として和訳したらそうなるかもですが。未規定にも "挙動は未規定" が1箇所ありますね (検索 未規定 挙動)。

Remarks: The result may be an undefined address, but the operations otherwise have no undefined behavior.

これは「未定義アドレス」とするしかないように思いますので、やはり用語定義 (GLOBAL_DEFINED_WORDS.json) から「未定義」を外し、許可された使用方法に「未定義アドレス」を加えることになりそうです。

@tshino さんの #1347 (comment) のブロック内コメントにもありましたが、この文脈だと、「未定義アドレス」は未定義の動作として挙げられているように読めるので、そういう意味では寧ろ `GLOBAL_DEFINED_WORDS.json "未定義" の部分が未定義の動作としてマークされた方が良いかもという気がします (理想は "アドレスは未定義動作になる" など言いかえることですが、アドレスが即動作になるわけではないので表現に困りますね…)。

問題は、未定義の動作と全く関係ない文脈で "未定義" と訳すしかないケースが存在するかどうかということの気がします。でも規格には undefined 〇〇 はたくさん出てきて、恐らく全て未定義の動作を imply しているのではないかという気がします (チェックはしてないですが)。

@faithandbrave
Copy link
Member Author

https://stackoverflow.com/questions/67433514/does-the-pointer-arithmetic-in-this-usage-cause-undefined-behavior

配列の要素へのポインタで、ポインタ加算の結果として配列の範囲外にでたら未定義動作になるのですかね (間接参照しなくても)。

@akinomyoga
Copy link
Member

akinomyoga commented Aug 29, 2024

確かに…。そういう意味でやはり未定義アドレスが即未定義の動作になるわけではなくて、間接参照した時に初めて未定義の動作になるわけですね…。ややこしいですね

Edit: すみません。未定義アドレスは未定義の動作じゃないよというご指摘かと思ったのですが早とちり(?)でした(?)。リンク先を読んだら範囲外になったら(終端点はセーフ)(間接参照しなくても) UB って書いてますね。間接参照しなければセーフだとなんとなく思ってました (アドレスのオーバーフローやアドレス空間が単純じゃない場合など考えたらそれはそうなのかも?)。

@tshino
Copy link
Contributor

tshino commented Aug 29, 2024

実行の結果として値が未定義アドレスになる場合、それは未定義の動作に当たる、という暗黙のルールがあるのであれば、読者としてはどこかにその情報が書いてあって欲しいですね。
(まさにここで議論になったように、自明には思えないので)

「未定義アドレス」を未定義の動作にエイリアスしてしまうのも手かも知れません。

@k-satoda
Copy link
Contributor

「未定義アドレス」に対応する "undefined address" については明確な意味付けが行われていない
ということで LWG issue 3906. "Undefined address" is undefined が挙がっています。
これが解決されるまでは、この状況を示す link, desc を持つ独立した用語として「未定義アドレス」を
登録しておくのがいいと思います。

@faithandbrave
Copy link
Member Author

一通り直してみました。確認お願いします。

Copy link
Contributor

@k-satoda k-satoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一通り見ました。挙げた点はいずれも修正が必要となる想定なので "Request changes" にしてみます。

Copy link
Member

@akinomyoga akinomyoga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"動作は未定義" を辞書 (GLOBAL_DEFINED_WORDS) に登録している一方で、"動作は未定義" → "未定義動作となる" という書き換えも幾つかあります。辞書に登録するなら "動作は未定義" はそのままで良いのではないでしょうか。

@faithandbrave
Copy link
Member Author

修正が入る箇所について、より用語らしく見える方を優先するよう寄せましたが、言い換えなのでどちらも許容ということでよいかと思います。

@faithandbrave
Copy link
Member Author

「未定義動作となる」をすべて「未定義動作を引き起こす」に修正しました

@akinomyoga
Copy link
Member

「~するプログラムは未定義動作となる。」→「~するプログラムは未定義動作を引き起こす」の提案は、この書き方だと "プログラム = 未定義動作" のように読めて変だったからでした。他の「未定義動作となる」については大丈夫だと思っていたのですが、まあ一貫させるという意味では全部「未定義動作を引き起こす」の方がわかりやすいのかもしれませんね。

@faithandbrave
Copy link
Member Author

faithandbrave commented Nov 7, 2024

@k-satoda
未定義アドレスの説明にダブルクォーテーションが含まれていてJSONとしてinvalidになっていたため、ダブルクォーテーションをなくしました。

また、「未定義アドレスが未定義動作ではないと考えられる」という文章を追加してあります。

Copy link
Contributor

@k-satoda k-satoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。
前回レビュー指摘箇所がそれぞれ問題無くなっていることを確認できたので Approve します。

@faithandbrave faithandbrave merged commit b947d3f into master Nov 11, 2024
12 checks passed
@faithandbrave faithandbrave deleted the defined_word_check branch November 11, 2024 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

未定義動作を表す「未定義」に「未定義動作」用語を使うようにする
4 participants