Skip to content

Commit 1f961de

Browse files
committed
C++23 : 「初期化文での型の別名宣言を許可」を追加 (close #1024)
1 parent 4029cd2 commit 1f961de

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
| P2266R3: [暗黙的なムーブを簡略化](/lang/cpp23/simpler_implicit_move.md.nolink) | 参照を返す関数の`return`文で暗黙的にムーブされない問題を修正 | 13 | 13 | 2022.2 | - |
253253
| P1787R6: [スコープと名前ルックアップの仕様整理](/lang/cpp23/declarations_and_where_to_find_them.md.nolink) | 複雑で不完全になっているスコープと名前ルックアップの仕様を整理し、一部の問題を解決する | - | - | - | - |
254254
| P2615R1: [無意味なexport宣言を禁止する](/lang/cpp23/meaningful_exports.md.nolink) | | - | - | - | - |
255-
| P2360R0: [初期化文での型の別名宣言を許可](/lang/cpp23/extend_init_statement_to_allow_alias_declaration.md.nolink) | `for (using T = int; T e : v) {}`を許可 | 12 | 14 | 2022.2 | - |
255+
| 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) | | - | - | - | - |
257257
| P2324R2: [関数末尾のラベルを許可](/lang/cpp23/labels_at_the_end_of_compound_statements.md.nolink) | C互換のため、関数末尾でのgoto文のラベルを許可する | 13 | 16 | 2023.2 | - |
258258
| P0847R7: [自身のオブジェクトを明示的にパラメータとして指定する](/lang/cpp23/deducing_this.md.nolink) | メンバ関数が`*this`の型・オブジェクトをパラメータとしてとり、`*this`オブジェクトがconst/非const、左辺値/右辺値であるかをメンバ関数内で識別できるようにする | - | 18 | - | 2022 Update 2 (partial) |

lang/cpp17/selection_statements_with_initializer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ if (it != m.end()) { return it->size(); }
205205
206206
## 関連項目
207207
- [C++20 初期化式をともなう範囲for文](/lang/cpp20/range-based_for_statements_with_initializer.md)
208+
- [C++23 初期化文での型の別名宣言を許可](/lang/cpp23/extend_init_statement_to_allow_alias_declaration.md)
208209
209210
210211
## 参照

lang/cpp20/range-based_for_statements_with_initializer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int main()
115115
116116
## 関連項目
117117
- [C++17 if文とswitch文の条件式と初期化を分離](/lang/cpp17/selection_statements_with_initializer.md)
118+
- [C++23 初期化文での型の別名宣言を許可](/lang/cpp23/extend_init_statement_to_allow_alias_declaration.md)
118119
119120
120121
## 参照

lang/cpp23.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
3030

3131
| 言語機能 | 説明 |
3232
|----------|------|
33-
| [初期化文での型の別名宣言を許可](cpp23/extend_init_statement_to_allow_alias_declaration.md.nolink) | `for (using T = int; T e : v) {}`を許可 |
33+
| [初期化文での型の別名宣言を許可](cpp23/extend_init_statement_to_allow_alias_declaration.md) | `for (using T = int; T e : v) {}`を許可 |
3434
| [範囲for文が範囲初期化子内で生じた一時オブジェクトを延命することを規定](cpp23/lifetime_extension_in_range_based_for_loop.md) | 範囲初期化子内で生じた一時オブジェクトは範囲for文の終わりまで延命される |
3535
| [関数末尾のラベルを許可](cpp23/labels_at_the_end_of_compound_statements.md.nolink) | C互換のため、関数末尾でのgoto文のラベルを許可する |
3636

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# 初期化文での型の別名宣言を許可
2+
* cpp23[meta cpp]
3+
4+
## 概要
5+
`if`文、`switch`文、範囲`for`文で初期化文を指定できるが、C++20までその初期化文では`typedef`による型の別名定義はできたが、`using`による型の別名定義はできなかった。
6+
7+
C++23では`using`による別名定義もまた初期化文でできるようになる。
8+
9+
10+
## 仕様
11+
初期化文 (init-statement) に、別名宣言 (alias-declaration) を追加 (`typedef`はsimple-declarationに含まれる)。
12+
13+
```
14+
init-statement:
15+
expression-statement
16+
simple-declaration
17+
alias-declaration
18+
```
19+
20+
##
21+
```cpp example
22+
#include <iostream>
23+
24+
int f() { return 1; }
25+
26+
int main()
27+
{
28+
// C++20 : OK
29+
if (typedef int T; T x = f()) {
30+
std::cout << x << std::endl;
31+
}
32+
33+
// C++20 : OK
34+
// C++23 : OK
35+
if (using T = int; T x = f()) {
36+
std::cout << x << std::endl;
37+
}
38+
}
39+
```
40+
41+
## 関連項目
42+
- [C++17 if文とswitch文の条件式と初期化を分離](/lang/cpp17/selection_statements_with_initializer.md)
43+
- [C++20 初期化式をともなう範囲for文](/lang/cpp20/range-based_for_statements_with_initializer.md)
44+
45+
46+
## 参照
47+
- [P2360R0 Extend init-statement to allow alias-declaration](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2360r0.html)

0 commit comments

Comments
 (0)