Skip to content

Commit 1666a75

Browse files
committed
C++23 : 「複合文の末尾へのラベルを許可」を追加 (close #1025)
1 parent a199a49 commit 1666a75

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
| P2615R1: [無意味なexport宣言を禁止する](/lang/cpp23/meaningful_exports.md.nolink) | | - | - | - | - |
255255
| P2360R0: [初期化文での型の別名宣言を許可](/lang/cpp23/extend_init_statement_to_allow_alias_declaration.md) | `for (using T = int; T e : v) {}`を許可 | 12 | 14 | 2022.2 | - |
256256
| P2718R0: [範囲for文が範囲初期化子内で生じた一時オブジェクトを延命することを規定](lang/cpp23/lifetime_extension_in_range_based_for_loop.md) | | - | - | - | - |
257-
| P2324R2: [関数末尾のラベルを許可](/lang/cpp23/labels_at_the_end_of_compound_statements.md.nolink) | C互換のため、関数末尾でのgoto文のラベルを許可する | 13 | 16 | 2023.2 | - |
257+
| P2324R2: [複合文の末尾へのラベルを許可](/lang/cpp23/labels_at_the_end_of_compound_statements.md) | C互換のため、複合文の末尾でのgoto文のラベルを許可する | 13 | 16 | 2023.2 | - |
258258
| P0847R7: [自身のオブジェクトを明示的にパラメータとして指定する](/lang/cpp23/deducing_this.md.nolink) | メンバ関数が`*this`の型・オブジェクトをパラメータとしてとり、`*this`オブジェクトがconst/非const、左辺値/右辺値であるかをメンバ関数内で識別できるようにする | - | 18 | - | 2022 Update 2 (partial) |
259259
| P1847R4: [アクセス制御の異なるメンバ変数のレイアウトを宣言順に規定](/lang/cpp23/make_declaration_order_layout_mandated.md.nolink) | アクセス制御の異なるメンバ変数のレイアウトが実装によって異なっていたため仕様を規定 | Yes | Yes | - | 2022 |
260260
| P2128R6: [添字演算子の多次元サポート](/lang/cpp23/multidimensional_subscript_operator.nd.nolink) | `operator[](int x, int y, int z)`のように添字演算子のオーバーロードで複数のパラメータをとることを許可 | 12 | 15 | 2022.2 | - |

lang/cpp23.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
3131
|----------|------|
3232
| [初期化文での型の別名宣言を許可](cpp23/extend_init_statement_to_allow_alias_declaration.md) | `for (using T = int; T e : v) {}`を許可 |
3333
| [範囲for文が範囲初期化子内で生じた一時オブジェクトを延命することを規定](cpp23/lifetime_extension_in_range_based_for_loop.md) | 範囲初期化子内で生じた一時オブジェクトは範囲for文の終わりまで延命される |
34-
| [関数末尾のラベルを許可](cpp23/labels_at_the_end_of_compound_statements.md.nolink) | C互換のため、関数末尾でのgoto文のラベルを許可する |
34+
| [複合文の末尾へのラベルを許可](cpp23/labels_at_the_end_of_compound_statements.md) | C互換のため、複合文の末尾でのgoto文のラベルを許可する |
3535

3636

3737
### クラス
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 複合文の末尾へのラベルを許可
2+
* cpp23[meta cpp]
3+
4+
## 概要
5+
C言語 (C20) との互換性のため、C言語で許可されていた複合文の末尾 (関数末尾など`{}`ブロックの末尾) へのgotoラベルを許可する。
6+
7+
関数末尾の例:
8+
9+
```cpp
10+
void foo(void)
11+
{
12+
first: // C20:OK C++:OK
13+
int x;
14+
second: // C20:OK C++:OK
15+
x = 1;
16+
last: // C20:OK C++23:OK
17+
}
18+
```
19+
20+
21+
## この機能が必要になった背景・経緯
22+
CではN2508の提案により、宣言の前など、複合文のあらゆる箇所にgotoラベルを置けるようになり、C++との互換性が改善した。C++では宣言は文として扱われるため宣言の前には以前からgotoラベルを置くことができた。ただし、C++では複合文の末尾にはgotoラベルを置けないという非互換が残っていた。
23+
24+
C++23でこの機能を導入することにより、gotoラベルを置ける場所についての非互換がなくなる。
25+
26+
27+
## 参照
28+
- [P2324R2 Labels at the end of compound statements (C compatibility)](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2324r2.pdf)
29+
- [C2X Proposal: WG14 N2508 Free Positioning of Labels Inside Compound Statements (updates N2496)](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf)

0 commit comments

Comments
 (0)