diff --git a/lang/cpp11/constexpr.md b/lang/cpp11/constexpr.md index 8be2183882..1220f6bc3d 100644 --- a/lang/cpp11/constexpr.md +++ b/lang/cpp11/constexpr.md @@ -131,6 +131,12 @@ constexpr int f(bool b) ## 備考 +### 標準ライブラリ関数への`constexpr`指定 +標準ライブラリの関数に`constexpr`が付くかどうかは、規格が明示的に要求している場合に限られる。処理系が独自の判断で、規格が要求していない標準ライブラリ関数のシグニチャに`constexpr`を付けることは許可されていない。 + +これは、ある処理系では定数式で使えるが別の処理系では使えない、といった移植性の問題を防ぐためである。 + + ### 浮動小数点数演算での注意 `constexpr`関数での浮動小数点数は、コンパイル時に実行するとコンパイル環境で計算が行われ、実行時に実行すると実行環境で計算が行われる。これによって、コンパイル時と実行時で、結果が異なる可能性がある。 @@ -234,3 +240,5 @@ GCC 5.2、Clang 3.7、Visual C++ 2015時点で、3つともデフォルトは512 - リテラル型のメンバ変数のみを持つクラスは、`constexpr`コンストラクタを明示的に定義しなくても、リテラル型となる - [CWG Issue 699. Must constexpr member functions be defined in the class member-specification?](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#699) - ゼロ割りの扱い、再帰回数の規定 +- [LWG Issue 2013. Do library implementers have the freedom to add `constexpr`?](https://cplusplus.github.io/LWG/issue2013) + - C++14で、処理系が規格の要求を超えて標準ライブラリ関数に`constexpr`を付けることは許可されないと規定された。処理系ごとに定数式で使える関数が異なると、移植性のあるプログラムを書けなくなるため diff --git a/reference/algorithm/nth_element.md b/reference/algorithm/nth_element.md index 603660c3ab..e3991f424b 100644 --- a/reference/algorithm/nth_element.md +++ b/reference/algorithm/nth_element.md @@ -55,7 +55,7 @@ namespace std { ## 効果 -`nth_element()` を呼び出した後、`nth` が指している位置の要素は、全ての範囲がソートされた場合の位置にある要素になる。そして、`[first,nth)` にあるイテレータ `i` と、`[nth,last)` にあるイテレータ `j` について、`!(*j < *i)` または `comp(*j, *i) == false` になる。 +`nth_element()` を呼び出した後、`nth` が指している位置の要素は、全ての範囲がソートされた場合の位置にある要素になる。ただし`nth == last`である場合、この規定は適用されない。そして、`[first,nth)` にあるイテレータ `i` と、`[nth,last)` にあるイテレータ `j` について、`!(*j < *i)` または `comp(*j, *i) == false` になる。 ## 戻り値 @@ -109,5 +109,8 @@ int main() - [LWG Issue 2163. `nth_element` requires inconsistent post-conditions](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2163) - C++11まで、この関数を呼び出したあとの状態について「`!(*i > *j)`」と記載していたが、並べ替えには`operator<()`を使用するので、C++14で「`!(*j < *i)`」に訂正。 - [LWG Issue 2150. Unclear specification of `find_end`](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2150) +- [LWG Issue 2339. Wording issue in `nth_element`](https://cplusplus.github.io/LWG/issue2339) + - C++14で、`nth == last`の場合には`nth`が指す位置の要素についての規定が適用されないことが明確化された + - この修正は欠陥報告(DR)であり、C++98以降に遡及して適用される。`nth == last`は終端イテレータであり指す要素が存在しないため、元の規定はそもそも意味を成さず、処理系は当初から現在の動作を採っていたため - [P0574R1 Algorithm Complexity Constraints and Parallel Overloads](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0574r1.html) - [P0879R0 Constexpr for `swap` and `swap` related functions](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0879r0.html) diff --git a/reference/algorithm/partition_copy.md b/reference/algorithm/partition_copy.md index 0b7bd9602b..edc52c96b7 100644 --- a/reference/algorithm/partition_copy.md +++ b/reference/algorithm/partition_copy.md @@ -50,7 +50,7 @@ namespace std { ## テンプレートパラメータ制約 -- `InputIterator` の value type は `Assignable` で、`out_true` と `out_false` の `OutputIterator` へ書き込み可能で、`Predicate` の引数型へ変換可能であること +- `InputIterator` の value type は `CopyAssignable` で、`out_true` と `out_false` の `OutputIterator` へ書き込み可能で、`Predicate` の引数型へ変換可能であること ## 事前条件 @@ -134,5 +134,8 @@ odds : 1,3,5, - [N2666 More STL algorithms (revision 2)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf) - [P0202R3 Add Constexpr Modifiers to Functions in `` and `` Headers](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html) - [P0467R2 Iterator Concerns for Parallel Algorithms](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0467r2.html) +- [LWG Issue 2357. Remaining "Assignable" requirement](https://cplusplus.github.io/LWG/issue2357) + - C++14で、要件の名前が、C++98から使われていた`Assignable`から`CopyAssignable`へ改められた + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。C++11で名前付き要件を改名した際に本関数への適用が漏れた編集上の誤りの修正であり、要件の内容そのものは変わらないため - [LWG Issue 4465. §[alg.partitions] Clarify _Returns:_ element](https://cplusplus.github.io/LWG/issue4465) - C++26で、戻り値の`pair`が、それぞれ`out_true`/`out_false`の各出力範囲へコピーされた最後の要素の次を指すイテレータであることが明確化された diff --git a/reference/atomic/atomic_thread_fence.md b/reference/atomic/atomic_thread_fence.md index 517da4ea67..3c30ea194d 100644 --- a/reference/atomic/atomic_thread_fence.md +++ b/reference/atomic/atomic_thread_fence.md @@ -96,6 +96,13 @@ assert(i == 1 || j == 1); // すなわち、i と j が共に0となることは 投げない +## 備考 +- アトミックオブジェクト`M`に対するアトミック変更`A`・`B`について、以下のいずれかが成り立つ場合、`B`は`M`の変更順序において`A`よりも後に発生する。ここで`S`は[`memory_order_seq_cst`](memory_order.md)操作の全順序である。 + - `A`が[`memory_order_seq_cst`](memory_order.md)フェンス`X`よりも前に順序付けられており、かつ`X`が`S`において`B`に先行する + - [`memory_order_seq_cst`](memory_order.md)フェンス`Y`が`B`よりも前に順序付けられており、かつ`A`が`S`において`Y`に先行する + - [`memory_order_seq_cst`](memory_order.md)フェンス`X`・`Y`が存在し、`A`が`X`よりも前に、`Y`が`B`よりも前に順序付けられており、かつ`X`が`S`において`Y`に先行する + + ## 例 ```cpp example #include @@ -148,6 +155,9 @@ int main() ## 参照 - [Implementing Dekker's algorithm with Fences](https://www.justsoftwaresolutions.co.uk/threading/implementing_dekkers_algorithm_with_fences.html) +- [LWG Issue 2130. Missing ordering constraints](https://cplusplus.github.io/LWG/issue2130) + - C++14で、[`memory_order_seq_cst`](memory_order.md)フェンスによる変更順序の制約が整理され、フェンスが片側にのみ存在する場合についても順序が規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。元の規定は両側にフェンスがある場合しか扱っておらず、フェンスと[`memory_order_seq_cst`](memory_order.md)操作を混在させたときの順序が規定から抜けていた記載漏れの補完であるため - [P3309R3 `constexpr atomic` and `atomic_ref`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3309r3.html) - C++26で`constexpr`に対応した - [P3475R2 Defang and deprecate memory_order::consume](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3475r2.pdf) diff --git a/reference/codecvt/codecvt_utf16.md b/reference/codecvt/codecvt_utf16.md index eca7d29043..8f27086390 100644 --- a/reference/codecvt/codecvt_utf16.md +++ b/reference/codecvt/codecvt_utf16.md @@ -11,11 +11,14 @@ namespace std { template class codecvt_utf16 : public codecvt { - // 未規定... + public: + explicit codecvt_utf16(size_t refs = 0); + ~codecvt_utf16(); }; } ``` * codecvt_mode[link /reference/codecvt/codecvt_mode.md] +* size_t[link /reference/cstddef/size_t.md] * codecvt[link /reference/locale/codecvt.md] ## 概要 @@ -90,5 +93,8 @@ int main() ## 参照 - [N2401 Code Conversion Facets for the Standard C++ Library](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2401.htm) +- [LWG Issue 2229. Standard code conversion facets underspecified](https://cplusplus.github.io/LWG/issue2229) + - C++14で、クラス定義が「未規定」ではなく、コンストラクタとデストラクタを持つことが明示された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。利用者がこれらのファセットを構築できることが規定上不明確だったものの明文化であり、処理系は当初からこれらを提供していたため - [P0618R0 Deprecating ``](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0618r0.html) - [P2871R3 Remove Deprecated Unicode Conversion Facets from C++26](https://open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2871r3.pdf) diff --git a/reference/codecvt/codecvt_utf8.md b/reference/codecvt/codecvt_utf8.md index d993a9dc15..c48640b204 100644 --- a/reference/codecvt/codecvt_utf8.md +++ b/reference/codecvt/codecvt_utf8.md @@ -11,11 +11,14 @@ namespace std { template class codecvt_utf8 : public codecvt { - // 未規定... + public: + explicit codecvt_utf8(size_t refs = 0); + ~codecvt_utf8(); }; } ``` * codecvt_mode[link /reference/codecvt/codecvt_mode.md] +* size_t[link /reference/cstddef/size_t.md] * codecvt[link /reference/locale/codecvt.md] ## 概要 @@ -90,5 +93,8 @@ int main() ## 参照 - [N2401 Code Conversion Facets for the Standard C++ Library](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2401.htm) +- [LWG Issue 2229. Standard code conversion facets underspecified](https://cplusplus.github.io/LWG/issue2229) + - C++14で、クラス定義が「未規定」ではなく、コンストラクタとデストラクタを持つことが明示された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。利用者がこれらのファセットを構築できることが規定上不明確だったものの明文化であり、処理系は当初からこれらを提供していたため - [P0618R0 Deprecating ``](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0618r0.html) - [P2871R3 Remove Deprecated Unicode Conversion Facets from C++26](https://open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2871r3.pdf) diff --git a/reference/codecvt/codecvt_utf8_utf16.md b/reference/codecvt/codecvt_utf8_utf16.md index b67766ec88..29cefdb265 100644 --- a/reference/codecvt/codecvt_utf8_utf16.md +++ b/reference/codecvt/codecvt_utf8_utf16.md @@ -11,11 +11,14 @@ namespace std { template class codecvt_utf8_utf16 : public codecvt { - // 未規定... + public: + explicit codecvt_utf8_utf16(size_t refs = 0); + ~codecvt_utf8_utf16(); }; } ``` * codecvt_mode[link /reference/codecvt/codecvt_mode.md] +* size_t[link /reference/cstddef/size_t.md] * codecvt[link /reference/locale/codecvt.md] ## 概要 @@ -90,5 +93,8 @@ int main() ## 参照 - [N2401 Code Conversion Facets for the Standard C++ Library](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2401.htm) +- [LWG Issue 2229. Standard code conversion facets underspecified](https://cplusplus.github.io/LWG/issue2229) + - C++14で、クラス定義が「未規定」ではなく、コンストラクタとデストラクタを持つことが明示された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。利用者がこれらのファセットを構築できることが規定上不明確だったものの明文化であり、処理系は当初からこれらを提供していたため - [P0618R0 Deprecating ``](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0618r0.html) - [P2871R3 Remove Deprecated Unicode Conversion Facets from C++26](https://open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2871r3.pdf) diff --git a/reference/condition_variable/condition_variable.md b/reference/condition_variable/condition_variable.md index f04ee62182..0f41c76508 100644 --- a/reference/condition_variable/condition_variable.md +++ b/reference/condition_variable/condition_variable.md @@ -22,6 +22,10 @@ namespace std { `condition_variable`の適切な利用については、[条件変数の利用方法](/article/lib/how_to_use_cv.md)も参照のこと。 +## 備考 +- 処理系は、[`notify_one()`](condition_variable/notify_one.md)・[`notify_all()`](condition_variable/notify_all.md)の全ての実行、および[`wait()`](condition_variable/wait.md)・[`wait_for()`](condition_variable/wait_for.md)・[`wait_until()`](condition_variable/wait_until.md)の実行の各部分が、単一の未規定な全順序で実行されるかのように振る舞う。この全順序は「happens before」の順序と一貫している。 + + ## メンバ関数 | 名前 | 説明 | 対応バージョン | @@ -129,3 +133,6 @@ process data ## 参照 - [Condition Variables - Operating Systems: Three Easy Pieces](http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf) +- [LWG Issue 2190. Condition variable specification](https://cplusplus.github.io/LWG/issue2190) + - C++14で、条件変数の操作が「ある未規定な全順序」ではなく「happens beforeの順序と一貫した単一の未規定な全順序」で実行されると規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。元の規定では複数の全順序が存在しうると読め、待機と通知の順序がプログラムの実行順序と矛盾することを許してしまっていたが、これは矛盾した文言の修正であり、処理系の動作は変わらないため diff --git a/reference/condition_variable/condition_variable/notify_all_at_thread_exit.md b/reference/condition_variable/condition_variable/notify_all_at_thread_exit.md index f981b4610d..711d690668 100644 --- a/reference/condition_variable/condition_variable/notify_all_at_thread_exit.md +++ b/reference/condition_variable/condition_variable/notify_all_at_thread_exit.md @@ -47,6 +47,10 @@ namespace std { 通知(`notify_all()`)を先に行い、その後でロックを解放するよう順序が変更された。これにより、`lk`のロック解除を待っている別スレッドは、`notify_all()`の呼び出し完了後にはじめて起床できるため、デタッチされたスレッドで`cond`が破棄されて`notify_all()`がダングリング参照になる競合を避けられる。 +## 同期操作 +暗黙に行われる`lk.`[`unlock()`](/reference/mutex/unique_lock/unlock.md)の呼び出しは、現在のスレッドに関連付けられたスレッドストレージ期間を持つ全てのオブジェクトの破棄より後に順序付けられる。 + + ## 戻り値 なし @@ -142,5 +146,8 @@ data is ready: true ## 参照 - [_at_thread_exit系の関数が存在している理由](/article/lib/at_thread_exit.md) - [N3070 - Handling Detached Threads and thread_local Variables](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3070.html) +- [LWG Issue 2140. Meaning of `notify_all_at_thread_exit` synchronization requirement?](https://cplusplus.github.io/LWG/issue2140) + - C++14で、同期の規定が「スレッドローカル変数のデストラクタの完了が`cond`を待っているスレッドと同期する」から「暗黙の`unlock()`がスレッドストレージ期間のオブジェクトの破棄より後に順序付けられる」という形へ改められた + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。元の規定は待機側スレッドが起床する条件を`notify_all()`ではなくデストラクタの完了に結び付けており実装不可能であって、処理系は当初から現在の動作を採っていたため - [LWG Issue 3343. Ordering of calls to `unlock()` and `notify_all()` in Effects element of `notify_all_at_thread_exit()` should be reversed](https://cplusplus.github.io/LWG/issue3343) - C++26で、通知処理の順序が`notify_all()`→`unlock()`へ変更された。デタッチされたスレッドで`cond`が破棄され`notify_all()`がダングリング参照となる競合を避けるためである。この変更は欠陥報告 (DR) であり、C++26より前のバージョンでもコンパイラが早期に対応している場合がある diff --git a/reference/future/async.md b/reference/future/async.md index 965109f822..7f5b1d4679 100644 --- a/reference/future/async.md +++ b/reference/future/async.md @@ -76,6 +76,8 @@ namespace std { - `policy & launch::deferred`が`0`でない場合、関数オブジェクト`f`をその場では実行せず、遅延状態にする - (`DECAY_COPY(std::`[`forward`](/reference/utility/forward.md)`(f))`と`DECAY_COPY(std::`[`forward`](/reference/utility/forward.md)`(args))...`を[`future`](future.md)オブジェクトとの共有状態に格納する)。 - この関数の戻り値である[`future`](future.md)オブジェクトの[`get()`](future/get.md)もしくは[`wait()`](future/wait.md)が呼び出されるタイミングで、関数オブジェクト`f`に`args...`を渡して実行する。 + - 関数オブジェクト`f`の戻り値が、共有状態に書き込まれる。 + - 関数オブジェクト`f`の内部で例外が投げられた場合は、共有状態に投げられた例外が設定される。 - 有効な実行ポリシーが指定されていない場合(整数値を`launch`型にキャストするような状況)、その動作は未定義(C++14)。 @@ -208,6 +210,9 @@ foo() = 3 - [<future> functions - Microsoft Docs](https://docs.microsoft.com/en-us/cpp/standard-library/future-functions?view=vs-2019#remarks) - [P2422R1 Remove `nodiscard` annotations from the standard library specification](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2422r1.html) - C++26で`[[nodiscard]]`指定が削除された +- [LWG Issue 2186. Incomplete action on `async`/`launch::deferred`](https://cplusplus.github.io/LWG/issue2186) + - C++14で、`launch::deferred`で遅延実行した場合にも、戻り値と送出された例外が共有状態へ格納されることが規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。`launch::async`側にのみ規定があり遅延実行の結果をどう扱うかが規定から抜けていた記載漏れの補完であり、処理系は当初から現在の動作を採っていたため - [LWG Issue 2752. Throws: clauses of `async` and `packaged_task` are unimplementable](https://cplusplus.github.io/LWG/issue2752) - 実装上必要な内部確保を反映し、`async`が[`bad_alloc`](/reference/new/bad_alloc.md)も送出しうることが規定された - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。型消去のための内部確保が必要なため元のThrows節は実装不可能であり、処理系は当初から`bad_alloc`を送出しえたため diff --git a/reference/future/packaged_task/op_call.md b/reference/future/packaged_task/op_call.md index fb0fbd6a86..449a1722a2 100644 --- a/reference/future/packaged_task/op_call.md +++ b/reference/future/packaged_task/op_call.md @@ -104,3 +104,5 @@ error! ## 参照 +- [LWG Issue 2142. `packaged_task::operator()` synchronization too broad?](https://cplusplus.github.io/LWG/issue2142) + - C++14で、この関数についての同期の規定が削除された。「`future`や`shared_future`のあらゆるメンバ関数の呼び出しと同期する」という規定は、タイムアウトで戻る[`wait_for()`](../future/wait_for.md)や[`wait_until()`](../future/wait_until.md)まで含んでしまい広すぎたため。共有状態そのものの規定で必要な同期は既に保証されている diff --git a/reference/istream/basic_istream/ignore.md b/reference/istream/basic_istream/ignore.md index 70130813c4..5296dd0fd0 100644 --- a/reference/istream/basic_istream/ignore.md +++ b/reference/istream/basic_istream/ignore.md @@ -80,6 +80,9 @@ TBD - C++98 ## 参照 +- [LWG Issue 2085. Wrong description of effect 1 of `basic_istream::ignore`](https://cplusplus.github.io/LWG/issue2085) + - C++14で、`n`文字を入力したという終了条件が「`n != numeric_limits::max()`であり、かつそこまでに`n`文字を入力した場合」であると明確化された + - この修正は欠陥報告(DR)であり、C++98以降に遡及して適用される。元の文言は「`n != numeric_limits::max()`ならば`n`文字を入力する」という条件文だったため、`n == numeric_limits::max()`のときは前提が偽となって条件が成り立ってしまい、1文字も入力せずに終了すると読めてしまっていた。処理系は当初から意図どおりの動作をしていたため - [P1264R2 Revising the wording of stream input operations](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1264r2.pdf) - C++23でローカルエラー状態の概念が導入され、入力関数のエラー処理セマンティクスが明確化された - [P3223R2 Making std::istream::ignore less surprising](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3223r2.html) diff --git a/reference/locale/messages_base.md b/reference/locale/messages_base.md index ca2fef9592..600bf1f834 100644 --- a/reference/locale/messages_base.md +++ b/reference/locale/messages_base.md @@ -18,7 +18,7 @@ namespace std { | 名前 | 説明 | |----------------------|----------------------------------------| -| `catalog` | 翻訳カタログ型 `int` | +| `catalog` | 翻訳カタログ型
・C++98 : `int`
・C++14 : 未規定の符号付き整数型 | ## 例 ```cpp example @@ -62,3 +62,8 @@ done ## 関連項目 - [`messages`](messages.md) - [`messages::open`](messages/open.md) + + +## 参照 +- [LWG Issue 2028. `messages_base::catalog` overspecified](https://cplusplus.github.io/LWG/issue2028) + - C++14で、`catalog`の型が`int`から未規定の符号付き整数型に変更された。POSIXのメッセージカタログAPIが使用する`nl_catd`は未規定の型であり(macOSでは`void*`)、`int`に固定すると処理系がOSの提供するメッセージカタログ機能をそのまま利用できなかったため diff --git a/reference/locale/num_put/do_put.md b/reference/locale/num_put/do_put.md index 37da3e8099..b1d3b5d0b8 100644 --- a/reference/locale/num_put/do_put.md +++ b/reference/locale/num_put/do_put.md @@ -122,3 +122,9 @@ Stage 3の終了時点での`charT`の列が、`*out++ = c`によって出力さ - [`num_put::put`](put.md) - [`numpunct`](/reference/locale/numpunct.md) - [`num_get::do_get`](/reference/locale/num_get/do_get.md) + + +## 参照 +- [LWG Issue 2293. Wrong facet used by `num_put::do_put`](https://cplusplus.github.io/LWG/issue2293) + - C++14で、`bool`版が[`truename()`](/reference/locale/numpunct/truename.md)・[`falsename()`](/reference/locale/numpunct/falsename.md)を取得するファセットが、[`ctype`](/reference/locale/ctype.md)から[`numpunct`](/reference/locale/numpunct.md)へ修正された + - この修正は欠陥報告(DR)であり、C++98以降に遡及して適用される。これらのメンバ関数を持つのは[`numpunct`](/reference/locale/numpunct.md)であり、[`ctype`](/reference/locale/ctype.md)を指定した元の規定は実装不可能だったため diff --git a/reference/ostream/basic_ostream/seekp.md b/reference/ostream/basic_ostream/seekp.md index a47d4f23cc..e267202e92 100644 --- a/reference/ostream/basic_ostream/seekp.md +++ b/reference/ostream/basic_ostream/seekp.md @@ -16,20 +16,38 @@ basic_ostream& seekp(off_type off, seekdir dir); // (2) ## 効果 -- (1) 出力ストリームの書き込み位置を `pos` に設定する。 -- (2) 出力ストリームの書き込み位置を `dir` を基準として相対位置 `off` に設定する。 +- (1) : + - 出力ストリームの書き込み位置を `pos` に設定する。 + - 設定に失敗した場合、[`setstate`](../../ios/basic_ios/setstate.md)`(failbit)`を呼び出す。 +- (2) : + - 出力ストリームの書き込み位置を `dir` を基準として相対位置 `off` に設定する。 + - 設定に失敗した場合の動作は、以下のようにバージョンによって異なる。 + - C++98 : ストリームの状態は変化しない。 + - C++14 : [`setstate`](../../ios/basic_ios/setstate.md)`(failbit)`を呼び出す。 ## 戻り値 `*this` ## 備考 -本関数の処理内容は以下の通り。 +- 本関数の処理内容は以下の通り。 + 1. [`sentry`](sentry.md) オブジェクトを構築する(C++11 以降のみ)。 + 1. 与えられた実引数により、以下のいずれかを実行する。 + - (1) [`rdbuf`](../../ios/basic_ios/rdbuf.md)`()->`[`pubseekpos`](../../streambuf/basic_streambuf/pubseekpos.md)`(pos, ios_base::out)` + - (2) [`rdbuf`](../../ios/basic_ios/rdbuf.md)`()->`[`pubseekoff`](../../streambuf/basic_streambuf/pubseekoff.md)`(off, dir, ios_base::out)` + 1. 処理に失敗した場合(上記の戻り値が `-1` だった場合)、[`setstate`](../../ios/basic_ios/setstate.md)`(failbit)`を呼び出す。 +- C++14より前の(2)には、この3番目の手順が規定されていなかった。そのため、位置の移動に失敗しても[`fail()`](../../ios/basic_ios/fail.md)は`false`のままとなり、呼び出し側は失敗を検知できなかった。移動できなかったことに気付かないまま出力を続けると、意図しない位置へ書き込んでしまう。 + ```cpp + os.seekp(-100, std::ios_base::cur); // シーク不能なストリームでは失敗する + + // C++98 : 失敗してもfail()はfalseのままであり、このifは実行されない + // C++14 : 失敗するとfailbitが設定され、このifが実行される + if (os.fail()) { + // 移動に失敗したことを検知できる + } + ``` + * seekp[color ff0000] + * os.fail()[link ../../ios/basic_ios/fail.md] -1. [`sentry`](sentry.md) オブジェクトを構築する(C++11 以降のみ)。 -1. 与えられた実引数により、以下のいずれかを実行する。 - - (1) [`rdbuf`](../../ios/basic_ios/rdbuf.md)`()->`[`pubseekpos`](../../streambuf/basic_streambuf/pubseekpos.md)`(pos, ios_base::out)` - - (2) [`rdbuf`](../../ios/basic_ios/rdbuf.md)`()->`[`pubseekoff`](../../streambuf/basic_streambuf/pubseekoff.md)`(off, dir, ios_base::out)` -1. 処理に失敗した場合(上記の戻り値が `-1` だった場合)、[`setstate`](../../ios/basic_ios/setstate.md)`(failbit)`を呼び出す。 ## 例 以下は、`off_type` と `seekdir` を使用する例。 @@ -72,7 +90,7 @@ basic_ostream& seekp(off_type off, seekdir dir) { sentry s(*this); if (!this->fail()) { if (this->rdbuf()->pubseekoff(off, dir, ios_base::out) == pos_type(-1)) { - this->setstate(failbit); + this->setstate(failbit); // C++14から } } return *this; @@ -94,3 +112,5 @@ basic_ostream& seekp(off_type off, seekdir dir) { - [`basic_ostream::tellp`](tellp.md) - [`basic_streambuf::pubseekpos`](../../streambuf/basic_streambuf/pubseekpos.md) - [`basic_streambuf::pubseekoff`](../../streambuf/basic_streambuf/pubseekoff.md) +- [LWG Issue 2341. Inconsistency between `basic_ostream::seekp(pos)` and `basic_ostream::seekp(off, dir)`](https://cplusplus.github.io/LWG/issue2341) + - C++14で、(2)の相対位置指定版についても、位置の移動に失敗した場合に`setstate(failbit)`を呼び出すことが規定された。(1)の絶対位置指定版のみに規定があり、(2)では失敗を検知する手段がなかったため diff --git a/reference/regex/basic_regex/mark_count.md b/reference/regex/basic_regex/mark_count.md index 00c2c3be76..9087cc21d4 100644 --- a/reference/regex/basic_regex/mark_count.md +++ b/reference/regex/basic_regex/mark_count.md @@ -53,3 +53,9 @@ int main() - [GCC](/implementation.md#gcc): 4.9.0 [mark verified], 4.9.1 [mark verified], 4.9.2 [mark verified], 5.0.0 [mark verified] - [ICC](/implementation.md#icc): ?? - [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [LWG Issue 2359. How does `regex_constants::nosubs` affect `basic_regex::mark_count()`?](https://cplusplus.github.io/LWG/issue2359) + - C++14で、[`regex_constants::nosubs`](../regex_constants/syntax_option_type.md)が「いかなる部分式もマークされたものとして扱わない」ことを指定するものであると明確化され、本関数が`0`を返すことが規定から導かれるようになった + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。`nosubs`が本関数へ及ぼす影響が未規定だったものの明文化であり、処理系は当初から`0`を返していたため diff --git a/reference/regex/regex_constants/syntax_option_type.md b/reference/regex/regex_constants/syntax_option_type.md index 64ead45968..aa9ce60902 100644 --- a/reference/regex/regex_constants/syntax_option_type.md +++ b/reference/regex/regex_constants/syntax_option_type.md @@ -45,7 +45,7 @@ namespace regex_constants { | 名前 | 説明 | 対応バージョン | |------|------|----------------| | `icase` | 正規表現のマッチで大文字小文字を区別しないことを指定する。 | C++11 | -| `nosubs` | 正規表現のマッチ成功時に、渡された[`match_results`](/reference/regex/match_results.md)オブジェクトへの参照に、部分式のマッチ情報を格納しないことを指定する | C++11 | +| `nosubs` | いかなる部分式もマークされたものとして扱わないことを指定する。これにより、正規表現のマッチ成功時に、渡された[`match_results`](/reference/regex/match_results.md)オブジェクトへの参照に、部分式のマッチ情報が格納されなくなる | C++11 | | `optimize` | 正規表現エンジンに、正規表現オブジェクトの構築速度よりもマッチ速度に注意を払うべきであることを指定する。 | C++11 | | `collate` | \[a-b\]形式の文字範囲がロケールを考慮することを指定する | C++11 | | `ECMAScript` | ECMA-262仕様第 3 版のECMAScript言語で使用されている正規表現と同じ構文を使用する | C++11 | @@ -79,5 +79,8 @@ namespace regex_constants { - 定数定義に不要な`static`が付いていたため、C++14で削除 - [LWG Issue 2330. regex("meow", regex::icase) is technically forbidden but should be permitted](http://cplusplus.github.io/LWG/lwg-defects.html#2330) - [`regex`](../basic_regex.md)`("meow", regex::icase)` のような指定を許可する +- [LWG Issue 2359. How does `regex_constants::nosubs` affect `basic_regex::mark_count()`?](https://cplusplus.github.io/LWG/issue2359) + - C++14で、`nosubs`が「いかなる部分式もマークされたものとして扱わない」ことを指定するものであると明確化された。これにより[`basic_regex::mark_count()`](/reference/regex/basic_regex/mark_count.md)が`0`を返すことが規定から導かれる + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。`nosubs`が[`basic_regex::mark_count()`](/reference/regex/basic_regex/mark_count.md)へ及ぼす影響が未規定だったものの明文化であり、処理系は当初から`0`を返していたため - [LWG Issue 2503. `multiline` option should be added to `syntax_option_type`](https://wg21.cmeerw.net/lwg/issue2503) - C++17で`multiline`オプションを追加 diff --git a/reference/regex/regex_traits/lookup_classname.md b/reference/regex/regex_traits/lookup_classname.md index 2f72728e8f..943d5df55e 100644 --- a/reference/regex/regex_traits/lookup_classname.md +++ b/reference/regex/regex_traits/lookup_classname.md @@ -94,4 +94,7 @@ int main() ## 参照 - [LWG Issue 2018. [CD] `regex_traits::isctype` Returns clause is wrong](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2018) - - C++14から、戻り値の仕様文面が見直された。 + - C++14で、戻り値の仕様文面が見直された +- [LWG Issue 2271. `regex_traits::lookup_classname` specification unclear](https://cplusplus.github.io/LWG/issue2271) + - C++14で、クラス名が認識できなかった場合の戻り値が、「`0`と等値比較できる値」から`char_class_type()`に変更された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。`char_class_type`はビットマスク型であり、ビットマスク型は[`bitset`](/reference/bitset/bitset.md)で実装してもよいため`0`と等値比較できるとは限らず、元の規定は実装不可能だったため diff --git a/reference/scoped_allocator/scoped_allocator_adaptor/construct.md b/reference/scoped_allocator/scoped_allocator_adaptor/construct.md index 712d6ccaf9..6f65d95ee9 100644 --- a/reference/scoped_allocator/scoped_allocator_adaptor/construct.md +++ b/reference/scoped_allocator/scoped_allocator_adaptor/construct.md @@ -69,9 +69,9 @@ apply( - [`uses_allocator`](/reference/memory/uses_allocator.md)`::value == false` かつ [`is_constructible`](/reference/type_traits/is_constructible.md)`::value == true` の場合 `x` を `xprime` とする。 - [`uses_allocator`](/reference/memory/uses_allocator.md)`::value == true` かつ [`is_constructible`](/reference/type_traits/is_constructible.md)`::value == true` の場合 - [`tuple_cat`](/reference/tuple/tuple_cat.md)`(`[`tuple`](/reference/tuple/tuple.md)`<`[`allocator_arg_t`](/reference/memory/allocator_arg_t.md)`, inner_allocator_type&>(`[`allocator_arg`](/reference/memory/allocator_arg_t.md)`, inner_allocator_type()), x)` を `xprime` とする。 + [`tuple_cat`](/reference/tuple/tuple_cat.md)`(`[`tuple`](/reference/tuple/tuple.md)`<`[`allocator_arg_t`](/reference/memory/allocator_arg_t.md)`, inner_allocator_type&>(`[`allocator_arg`](/reference/memory/allocator_arg_t.md)`,` [`inner_allocator`](inner_allocator.md)`()),` [`move`](/reference/utility/move.md)`(x))` を `xprime` とする。 - [`uses_allocator`](/reference/memory/uses_allocator.md)`::value == true` かつ [`is_constructible`](/reference/type_traits/is_constructible.md)`::value == true` の場合 - [`tuple_cat`](/reference/tuple/tuple_cat.md)`(x,` [`tuple`](/reference/tuple/tuple.md)`(inner_allocator_type()))` を `xprime` とする。 + [`tuple_cat`](/reference/tuple/tuple_cat.md)`(`[`move`](/reference/utility/move.md)`(x),` [`tuple`](/reference/tuple/tuple.md)`(`[`inner_allocator`](inner_allocator.md)`()))` を `xprime` とする。 - それ以外の場合、プログラムは不適格となる。 - (3) : 以下と等価の動作を行う。 @@ -235,6 +235,9 @@ int main() ## 参照 - [P0591R4 Utility functions to implement uses-allocator construction](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0591r4.pdf) +- [LWG Issue 2203. `scoped_allocator_adaptor` uses wrong argument types for piecewise construction](https://cplusplus.github.io/LWG/issue2203) + - C++14で、`xprime`/`yprime`の構築において、引数の`tuple`を[`move`](/reference/utility/move.md)で渡すようになり、内側のアロケータの取得も`inner_allocator_type()`(デフォルト構築した一時オブジェクト)ではなく[`inner_allocator()`](inner_allocator.md)(実際に保持しているアロケータ)を使うよう修正された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。元の規定は右辺値`inner_allocator_type()`を`inner_allocator_type&`へ束縛するもので、そもそもコンパイルできない実装不可能な文言だったため - [LWG Issue 2975. Missing case for pair construction in scoped and polymorphic allocators](https://wg21.cmeerw.net/lwg/issue2975) - [LWG Issue 3116. `OUTERMOST_ALLOC_TRAITS` needs `remove_reference_t`](https://cplusplus.github.io/LWG/issue3116) - C++20で、`OUTERMOST(x)`が参照を返しうることに対応し、`OUTERMOST_ALLOC_TRAITS`の定義に[`remove_reference_t`](/reference/type_traits/remove_reference.md)が挿入された diff --git a/reference/string/basic_string/op_ostream.md b/reference/string/basic_string/op_ostream.md index a7db4fc65c..36776c65af 100644 --- a/reference/string/basic_string/op_ostream.md +++ b/reference/string/basic_string/op_ostream.md @@ -17,10 +17,14 @@ namespace std { 文字列をストリームへ出力する。 ## 効果 +書式化出力関数として振る舞う。 + 1. `sentry`オブジェクトを構築する。`sentry`オブジェクトが失敗を示した場合、何もしない。 -1. 仮引数`s`が指し示す文字列を出力する。 - - `width()`と`flags() & (ios_base::adjustfield)`に従ってパディングの出力も行う。 -1. `width(0)`を呼び出す。 +1. 出力する文字列を決定する。初期状態はイテレータ範囲`[s.`[`begin()`](begin.md)`, s.`[`end()`](end.md)`)`の要素からなる文字列である。 + - `s.`[`size`](size.md)`()`が`os.`[`width`](/reference/ios/ios_base/width.md)`()`より小さい場合、`os.`[`width`](/reference/ios/ios_base/width.md)`()`文字の幅になるまで、必要な数の`os.`[`fill`](/reference/ios/basic_ios/fill.md)`()`をこの文字列へ追加する。 + - `(os.`[`flags`](/reference/ios/ios_base/flags.md)`() & `[`std::ios_base::adjustfield`](/reference/ios/ios_base/type-fmtflags.md)`) == `[`std::ios_base::left`](/reference/ios/ios_base/type-fmtflags.md)である場合、埋め文字は文字列の後ろに置かれる。そうでない場合は前に置かれる。 +1. 上記で得られた文字列`seq`を、`os.`[`rdbuf`](/reference/ios/basic_ios/rdbuf.md)`()->`[`sputn`](/reference/streambuf/basic_streambuf/sputn.md)`(seq, n)`を呼び出したかのようにして出力する。ここで`n`は`os.`[`width`](/reference/ios/ios_base/width.md)`()`と`s.`[`size`](size.md)`()`のうち大きい方である。 +1. `os.`[`width`](/reference/ios/ios_base/width.md)`(0)`を呼び出す。 ## 戻り値 `os` @@ -51,3 +55,6 @@ TBD ## 参照 - このほかの`<<`演算子関数 - [``ヘッダで定義されているもの](../../ostream/basic_ostream/op_ostream.md) +- [LWG Issue 2011. Unexpected output required of strings](https://cplusplus.github.io/LWG/issue2011) + - C++14で、パディングの決定方法がこの関数自身の規定として明記された + - この修正は欠陥報告(DR)であり、C++98以降に遡及して適用される。元の規定は数値出力のための[`num_put::do_put`](/reference/locale/num_put/do_put.md)の「Fill padding」表を参照していたため、[`std::ios_base::internal`](/reference/ios/ios_base/type-fmtflags.md)指定時に`"0X1Y2Z"`が`"0X**1Y2Z"`と出力されることを要求していたが、処理系は当初から`"**0X1Y2Z"`を出力していたため diff --git a/reference/unordered_map/unordered_map/erase.md b/reference/unordered_map/unordered_map/erase.md index 2b68b0de27..f500aaf11a 100644 --- a/reference/unordered_map/unordered_map/erase.md +++ b/reference/unordered_map/unordered_map/erase.md @@ -57,7 +57,8 @@ constexpr iterator erase(const_iterator first, const_iterator last); // (4) C++2 ## 備考 -削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除されなかった要素の相対順序は維持される。 ## 例 @@ -219,4 +220,7 @@ int main() - [N2350 Container insert/erase and iterator constness (Revision 1)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2350.pdf) - [LWG Issue 2059. C++0x ambiguity problem with `map::erase`](https://cplusplus.github.io/LWG/issue2059) - C++17で、`erase(iterator)`を追加 +- [LWG Issue 2356. Stability of erasure in unordered associative containers](https://cplusplus.github.io/LWG/issue2356) + - C++14で、`erase()`が削除されなかった要素の相対順序を維持することが規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。イテレータの無効化についての規定はあったものの残った要素の並び順が維持されるかが未規定だったものの明文化であり、処理系は当初から相対順序を維持していたため - [P3372R3 constexpr containers and adaptors](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3372r3.html) diff --git a/reference/unordered_map/unordered_multimap/erase.md b/reference/unordered_map/unordered_multimap/erase.md index ba3822dc3c..2663f7c38d 100644 --- a/reference/unordered_map/unordered_multimap/erase.md +++ b/reference/unordered_map/unordered_multimap/erase.md @@ -57,7 +57,8 @@ constexpr iterator erase(const_iterator first, const_iterator last); // (4) C++2 ## 備考 -削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除されなかった要素の相対順序は維持される。 ## 例 @@ -221,4 +222,7 @@ int main() - 安定性の保証が規定された経緯のレポート - [LWG Issue 2059. C++0x ambiguity problem with `map::erase`](https://cplusplus.github.io/LWG/issue2059) - C++17で、`erase(iterator)`を追加 +- [LWG Issue 2356. Stability of erasure in unordered associative containers](https://cplusplus.github.io/LWG/issue2356) + - C++14で、`erase()`が削除されなかった要素の相対順序を維持することが規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。イテレータの無効化についての規定はあったものの残った要素の並び順が維持されるかが未規定だったものの明文化であり、処理系は当初から相対順序を維持していたため - [P3372R3 constexpr containers and adaptors](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3372r3.html) diff --git a/reference/unordered_set/unordered_multiset/erase.md b/reference/unordered_set/unordered_multiset/erase.md index 7772e18541..9c15ea1c16 100644 --- a/reference/unordered_set/unordered_multiset/erase.md +++ b/reference/unordered_set/unordered_multiset/erase.md @@ -57,7 +57,8 @@ constexpr iterator erase(const_iterator first, const_iterator last); // (4) C++2 ## 備考 -削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除されなかった要素の相対順序は維持される。 ## 例 @@ -207,6 +208,9 @@ int main() - 安定性の保証が規定された経緯のレポート - [LWG Issue 2059. C++0x ambiguity problem with `map::erase`](https://cplusplus.github.io/LWG/issue2059) - C++17で、`erase(iterator)`を追加 +- [LWG Issue 2356. Stability of erasure in unordered associative containers](https://cplusplus.github.io/LWG/issue2356) + - C++14で、`erase()`が削除されなかった要素の相対順序を維持することが規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。イテレータの無効化についての規定はあったものの残った要素の並び順が維持されるかが未規定だったものの明文化であり、処理系は当初から相対順序を維持していたため - [LWG Issue 3704. LWG 2059 added overloads that might be ill-formed for sets](https://cplusplus.github.io/LWG/issue3704) - C++23で、`iterator`と`const_iterator`が同一型のときにオーバーロード(1)と(2)が曖昧になる問題を避けるため、`erase(iterator)`(1)に`!same_as`の制約が追加された - [P3372R3 constexpr containers and adaptors](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3372r3.html) diff --git a/reference/unordered_set/unordered_set/erase.md b/reference/unordered_set/unordered_set/erase.md index 35444b1c43..39407efa3b 100644 --- a/reference/unordered_set/unordered_set/erase.md +++ b/reference/unordered_set/unordered_set/erase.md @@ -57,7 +57,8 @@ constexpr iterator erase(const_iterator first, const_iterator last); // (4) C++2 ## 備考 -削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除された要素を指すイテレータ、および、参照のみ無効になる。なお、規格書に明確な記載は無いが、削除された要素を指すポインタも無効になる。 +- 削除されなかった要素の相対順序は維持される。 ## 例 @@ -205,6 +206,9 @@ int main() - [N2350 Container insert/erase and iterator constness (Revision 1)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2350.pdf) - [LWG Issue 2059. C++0x ambiguity problem with `map::erase`](https://cplusplus.github.io/LWG/issue2059) - C++17で、`erase(iterator)`を追加 +- [LWG Issue 2356. Stability of erasure in unordered associative containers](https://cplusplus.github.io/LWG/issue2356) + - C++14で、`erase()`が削除されなかった要素の相対順序を維持することが規定された + - この修正は欠陥報告(DR)であり、C++11以降に遡及して適用される。イテレータの無効化についての規定はあったものの残った要素の並び順が維持されるかが未規定だったものの明文化であり、処理系は当初から相対順序を維持していたため - [LWG Issue 3704. LWG 2059 added overloads that might be ill-formed for sets](https://cplusplus.github.io/LWG/issue3704) - C++23で、`iterator`と`const_iterator`が同一型のときにオーバーロード(1)と(2)が曖昧になる問題を避けるため、`erase(iterator)`(1)に`!same_as`の制約が追加された - [P3372R3 constexpr containers and adaptors](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3372r3.html)