Skip to content

Commit 90e27bd

Browse files
C++26対応として定数式での例外送出を許可 (#1432)
1 parent 7ae4be4 commit 90e27bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+833
-79
lines changed

implementation-status.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
| P2963R3: [制約式内での畳み込み式の順序付け](/lang/cpp26/ordering_of_constraints_involving_fold_expressions.md.nolink) | 畳み込み式では全体ではなく個別の制約を原子制約式として扱う | | 19 | | |
315315
| P0963R3: [条件式での構造化束縛の使用を許可](/lang/cpp26/structured_binding_declaration_as_a_condition.md) | 式全体を`bool`値に変換できる場合に条件式で構造化束縛を使用できることとする | 15 | | | |
316316
| P2686R5: [`constexpr`構造化束縛の許可と、定数式への参照を定数式とする](/lang/cpp26/constexpr_structured_bindings_and_references_to_constexpr_variables.md.nolink) | 定数式に対する構造化束縛を許可し、関連する定数式への参照が定数式になるようにする | 15 | | | |
317-
| P3068R6: [定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md.nolink) | 定数式の文脈での例外の送出と捕捉を許可 | | | | |
317+
| P3068R6: [定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md) | 定数式の文脈での例外の送出と捕捉を許可 | | | | |
318318
| P2865R6: [非推奨だった配列の比較を削除](/lang/cpp26/remove_deprecated_array_comparisons.md.nolink) | C++20で非推奨となっていた配列比較を削除 | 15 | 20 | | |
319319
| P1061R10: [構造化束縛でパックを導入できるようにする](/lang/cpp26/structured_bindings_can_introduce_a_pack.md.nolink) | タプルを分解する際に複数の変数をパックとして宣言できるようにする。`auto [a, ...xs] = f();` | | | | |
320320
| P3176R0: [先行するカンマのない省略記号を非推奨化](/lang/cpp26/the_oxford_variadic_comma.md.nolink) | `void f(int, ...);`はOK。`void f(int...);`は非推奨 | 15 | 20 | | |

lang/cpp11/constexpr.md

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ GCC 5.2、Clang 3.7、Visual C++ 2015時点で、3つともデフォルトは512
215215
- [C++23 `constexpr`関数が定数実行できない場合でも適格とする](/lang/cpp23/relaxing_some_constexpr_restrictions.md)
216216
- [C++23 `constexpr`関数内での`static constexpr`変数を許可](/lang/cpp23/permitting_static_constexpr_variables_in_constexpr_functions.md)
217217
- [C++23 `constexpr`関数内で`consteval`関数を呼び出せない問題を軽減](/lang/cpp23/consteval_needs_to_propagate_up.md)
218+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
218219
219220
220221
## 参照

lang/cpp26.md

+19-15
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ C++26とは、2026年中に改訂される予定の、C++バージョンの通
8181
| [`static_assert`の診断メッセージにユーザーが生成した文字列の指定を許可](/lang/cpp26/user-generated_static_assert_messages.md) | `constexpr``S.size()``S.data()`メンバ関数をもつオブジェクトをコンパイル時文字列として指定できるようにする |
8282
| [`constexpr`配置`new`](/lang/cpp26/constexpr_placement_new.md.nolink) | 定数式の文脈での配置`new`を許可 |
8383
| [`constexpr`構造化束縛の許可と、定数式への参照を定数式とする](/lang/cpp26/constexpr_structured_bindings_and_references_to_constexpr_variables.md.nolink) | 定数式に対する構造化束縛を許可し、関連する定数式への参照が定数式になるようにする |
84-
| [定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md.nolink) | 定数式の文脈での例外の送出と捕捉を許可 |
84+
| [定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md) | 定数式の文脈での例外の送出と捕捉を許可 |
8585

8686

8787
### プリプロセッサ
@@ -404,22 +404,26 @@ C++26とは、2026年中に改訂される予定の、C++バージョンの通
404404
- [`<typeinfo>`](/reference/typeinfo.md)ヘッダの以下の機能
405405
- [`std::bad_cast`](/reference/typeinfo/bad_cast.md)クラスの`what()`メンバ関数
406406
- [`std::bad_typeid`](/reference/typeinfo/bad_typeid.md)クラスの`what()`メンバ関数
407+
- [`<stdexcept>`](/reference/stdexcept.md)ヘッダの以下の機能
408+
- [`std::domain_error`](/reference/stdexcept.md)
409+
- [`std::invalid_argument`](/reference/stdexcept.md)
410+
- [`std::length_error`](/reference/stdexcept.md)
411+
- [`std::logic_error`](/reference/stdexcept.md)
412+
- [`std::out_of_range`](/reference/stdexcept.md)
413+
- [`std::runtime_error`](/reference/stdexcept.md)
414+
- [`std::range_error`](/reference/stdexcept.md)
415+
- [`std::overflow_error`](/reference/stdexcept.md)
416+
- [`std::underflow_error`](/reference/stdexcept.md)
417+
- [`<expected>`](/reference/expected.md)ヘッダの以下の機能
418+
- [`std::bad_expected_access`](/reference/expected/bad_expected_access.md)
419+
- [`<optional>`](/reference/optional.md)ヘッダの以下の機能
420+
- [`std::bad_optional_access`](/reference/optional/bad_optional_access.md)
421+
- [`<variant>`](/reference/variant.md)ヘッダの以下の機能
422+
- [`std::bad_variant_access`](/reference/variant/bad_variant_access.md)
423+
- [`<format>`](/reference/format.md)ヘッダの以下の機能
424+
- [`std::format_error`](/reference/format/format_error.md)
407425
- [`<memory>`](/reference/memory.md)に、ポインタのアライメントを判定する[`std::is_sufficiently_aligned()`](/reference/memory/is_sufficiently_aligned.md)関数を追加。
408426
- [`<utility>`](/reference/utility.md)に、タイムトラベル最適化を抑止するための観測可能ポイントとして[`std::observable()`](/reference/utility/observable.md.nolink)を追加
409-
- 以下の例外型を`constexpr`対応
410-
- [`std::domain_error`](/reference/stdexcept.md)
411-
- [`std::invalid_argument`](/reference/stdexcept.md)
412-
- [`std::length_error`](/reference/stdexcept.md)
413-
- [`std::logic_error`](/reference/stdexcept.md)
414-
- [`std::out_of_range`](/reference/stdexcept.md)
415-
- [`std::runtime_error`](/reference/stdexcept.md)
416-
- [`std::range_error`](/reference/stdexcept.md)
417-
- [`std::overflow_error`](/reference/stdexcept.md)
418-
- [`std::underflow_error`](/reference/stdexcept.md)
419-
- [`std::bad_expected_access`](/reference/expected/bad_expected_access.md)
420-
- [`std::bad_optional_access`](/reference/optional/bad_optional_access.md)
421-
- [`std::bad_variant_access`](/reference/variant/bad_variant_access.md)
422-
- [`std::format_error`](/reference/format/format_error.md)
423427

424428

425429
### デバッグ
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# 定数評価での例外送出を許可 [P3068R6]
2+
* cpp26[meta cpp]
3+
4+
<!-- start lang caution -->
5+
6+
このページはC++26に採用される見込みの言語機能の変更を解説しています。
7+
8+
のちのC++規格でさらに変更される場合があるため[関連項目](#relative-page)を参照してください。
9+
10+
<!-- last lang caution -->
11+
12+
## 概要
13+
C++23まで、定数式内での例外送出、そのコードに到達した時点でコンパイルエラーとなっていた。
14+
15+
C++26からは定数式内での例外送出ができるようになり、ユーザーはその例外を捕捉できるようになる。
16+
17+
```cpp
18+
consteval auto hello(std::string_view input) {
19+
if (input.empty()) {
20+
throw invalid_argument{"empty name provided"}; // C++23: このコードに到達した時点でthrow式側でコンパイルエラー
21+
}
22+
23+
return concat_into_a_fixed_string("hello ",input);
24+
}
25+
26+
const auto a = hello(""); // C++26: 呼び出し側でコンパイルエラー
27+
const auto b = hello("Hana");
28+
29+
try {
30+
const auto c = hello(""); // C++26: 例外を捕捉
31+
} catch (const validation_error &) {
32+
// everything is fine
33+
}
34+
35+
// C++23: concat関数の深い場所にあるthrow式側でコンパイルエラー
36+
// C++26: 呼び出し側で「文字列が長すぎる」のようなコンパイルエラーになる
37+
const auto d = hello("Adolph Blaine Charles David Earl Frederick Gerald Hubert Irvin John Kenneth Lloyd Martin Nero Oliver Paul Quincy Randolph Sherman Thomas Uncas Victor William Xerxes Yancy Zeus");
38+
```
39+
40+
41+
42+
## <a id="relative-page" href="#relative-page">関連項目</a>
43+
- [C++11 constexpr](/lang/cpp11/constexpr.md)
44+
- [`std::exception`](/reference/exception/exception.md)
45+
- [`std::nested_exception`](/reference/exception/nested_exception.md)
46+
- [`std::bad_exception`](/reference/exception/bad_exception.md)
47+
- [`std::uncaught_exceptions()`](/reference/exception/uncaught_exceptions.md)
48+
- [`std::current_exception()`](/reference/exception/current_exception.md)
49+
- [`std::rethrow_exception()`](/reference/exception/rethrow_exception.md)
50+
- [`std::make_exception_ptr()`](/reference/exception/make_exception_ptr.md)
51+
- [`std::throw_with_nested()`](/reference/exception/throw_with_nested.md)
52+
- [`std::rethrow_if_nested()`](/reference/exception/rethrow_if_nested.md)
53+
- [`std::bad_alloc`](/reference/new/bad_alloc.md)
54+
- [`std::bad_array_new_length`](/reference/new/bad_array_new_length.md)
55+
- [`std::bad_cast`](/reference/typeinfo/bad_cast.md)
56+
- [`std::bad_typeid`](/reference/typeinfo/bad_typeid.md)
57+
58+
59+
## 参照
60+
- [P3068R6 Allowing exception throwing in constant-evaluation](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3068r6.html)

reference/exception/bad_exception.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ namespace std {
3131
## メンバ関数
3232
3333
| 名前 | 説明 | 対応バージョン |
34-
|----------------------------------------------|-----------------------------------------------|-------|
35-
| `bad_exception() noexcept;` `bad_exception(const bad_exception&) noexcept;` | コンストラクタ | |
36-
| `virtual ~bad_exception() = default;` | デストラクタ | |
37-
| `bad_exception& operator=(const bad_exception&) noexcept;` | 代入演算子 | |
38-
| `virtual const char* what() const noexcept;` | 実装定義のエラー内容を取得する | |
34+
|------|------|----------------|
35+
| [(constructor)](bad_exception/op_constructor.md) | コンストラクタ | |
36+
| [(destructor)](bad_exception/op_destructor.md) | デストラクタ | |
37+
| [`operator=`](bad_exception/op_assign.md) | 代入演算子 | |
38+
| [`what`](bad_exception/what.md) | エラー理由を取得する | |
3939
4040
4141
## 例
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# operator=
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* bad_exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
bad_exception& operator=(const bad_exception&); // (1) C++03
9+
bad_exception& operator=(const bad_exception&) noexcept; // (1) C++11
10+
constexpr bad_exception& operator=(const bad_exception&) noexcept; // (1) C++26
11+
```
12+
13+
## 概要
14+
`bad_exception`オブジェクトを代入する
15+
16+
- (1) : コピー代入
17+
18+
19+
## 例外
20+
投げない
21+
22+
23+
## 関連項目
24+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# コンストラクタ
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* bad_exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
bad_exception(); // (1) C++03
9+
bad_exception() noexcept; // (1) C++11
10+
constexpr bad_exception() noexcept; // (1) C++26
11+
12+
bad_exception(const bad_exception&); // (2) C++03
13+
bad_exception(const bad_exception&) noexcept; // (2) C++11
14+
constexpr bad_exception(const bad_exception&) noexcept; // (2) C++26
15+
```
16+
17+
## 概要
18+
`bad_exception`オブジェクトを構築する。
19+
20+
- (1) : デフォルトコンストラクタ
21+
- (2) : コピーコンストラクタ
22+
23+
24+
## 例外
25+
投げない
26+
27+
28+
## 関連項目
29+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# デストラクタ
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* bad_exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
virtual ~bad_exception(); // (1) C++03
9+
constexpr virtual ~bad_exception(); // (1) C++26
10+
```
11+
12+
## 概要
13+
`bad_exception`オブジェクトを破棄する。
14+
15+
16+
## 例外
17+
投げない
18+
19+
20+
## 関連項目
21+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
22+
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# what
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* bad_exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
virtual const char* what() const; // (1) C++03
9+
virtual const char* what() const noexcept; // (1) C++11
10+
const char* what() const noexcept override; // (1) C++17
11+
constexpr const char* what() const noexcept override; // (1) C++26
12+
```
13+
14+
## 概要
15+
エラー理由となる実装依存文字列を取得する。
16+
17+
18+
## 例外
19+
投げない
20+
21+
22+
## 関連項目
23+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
24+

reference/exception/current_exception.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
```cpp
88
namespace std {
9-
exception_ptr current_exception() noexcept;
9+
exception_ptr current_exception() noexcept; // (1) C++11
10+
constexpr exception_ptr current_exception() noexcept; // (1) C++26
1011
}
1112
```
1213
* exception_ptr[link exception_ptr.md]
@@ -85,6 +86,10 @@ terminate called after throwing an instance of 'std::runtime_error'
8586
- [Visual C++](/implementation.md#visual_cpp): 2010 [mark verified], 2012 [mark verified], 2013 [mark verified], 2015 [mark verified]
8687

8788

89+
## 関連項目
90+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
91+
92+
8893
## 参照
8994
- [N2179 Language Support for Transporting Exceptions between Threads](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html)
9095
- [Can I use `std::current_exception` during stack unwinding? - StackOverflow](http://stackoverflow.com/questions/28267484/can-i-use-stdcurrent-exception-during-stack-unwinding)

reference/exception/exception.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ namespace std {
1818
## メンバ関数
1919
2020
| 名前 | 説明 | 対応バージョン |
21-
|----------------------------------------|---------------------------------------------|-------|
22-
| `exception() noexcept;`<br/>`exception(const exception&) noexcept;` | コンストラクタ | |
23-
| `virtual ~exception();` | デストラクタ | |
24-
| `exception& operator=(const exception&) noexcept;` | 代入演算子 | |
25-
| `virtual const char* what() const noexcept;` | 実装定義のエラー内容を取得する | |
21+
|------|------|----------------|
22+
| [(constructor)](exception/op_constructor.md) | コンストラクタ | |
23+
| [(destructor)](exception/op_destructor.md) | デストラクタ | |
24+
| [`operator=`](exception/op_assign.md) | 代入演算子 | |
25+
| [`what`](exception/what.md) | エラー理由を取得する | |
2626
2727
2828
## 例
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# operator=
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
exception& operator=(const exception&); // (1) C++03
9+
exception& operator=(const exception&) noexcept; // (1) C++11
10+
constexpr exception& operator=(const exception&) noexcept; // (1) C++26
11+
```
12+
13+
## 概要
14+
`exception`オブジェクトを代入する
15+
16+
- (1) : コピー代入
17+
18+
19+
## 例外
20+
投げない
21+
22+
23+
## 関連項目
24+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# コンストラクタ
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
exception(); // (1) C++03
9+
exception() noexcept; // (1) C++11
10+
constexpr exception() noexcept; // (1) C++26
11+
12+
exception(const exception&); // (2) C++03
13+
exception(const exception&) noexcept; // (2) C++11
14+
constexpr exception(const exception&) noexcept; // (2) C++26
15+
```
16+
17+
## 概要
18+
`exception`オブジェクトを構築する。
19+
20+
- (1) : デフォルトコンストラクタ
21+
- (2) : コピーコンストラクタ
22+
23+
24+
## 例外
25+
投げない
26+
27+
28+
## 関連項目
29+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# デストラクタ
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
virtual ~exception(); // (1) C++03
9+
constexpr virtual ~exception(); // (1) C++26
10+
```
11+
12+
## 概要
13+
`exception`オブジェクトを破棄する。
14+
15+
16+
## 例外
17+
投げない
18+
19+
20+
## 関連項目
21+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
22+

reference/exception/exception/what.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# what
2+
* exception[meta header]
3+
* std[meta namespace]
4+
* exception[meta class]
5+
* function[meta id-type]
6+
7+
```cpp
8+
virtual const char* what() const; // (1) C++03
9+
virtual const char* what() const noexcept; // (1) C++11
10+
const char* what() const noexcept override; // (1) C++17
11+
constexpr const char* what() const noexcept override; // (1) C++26
12+
```
13+
14+
## 概要
15+
エラー理由となる実装依存文字列を取得する。
16+
17+
18+
## 例外
19+
投げない
20+
21+
22+
## 関連項目
23+
- [C++26 定数評価での例外送出を許可](/lang/cpp26/allowing_exception_throwing_in_constant-evaluation.md)
24+

0 commit comments

Comments
 (0)