Skip to content

Commit

Permalink
noexcept : 指定可能な位置について追記
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Apr 17, 2023
1 parent 5eaa8ee commit 3744030
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lang/cpp11/noexcept.md
Expand Up @@ -56,13 +56,16 @@ struct X {
// 例外を送出しない
int getValue() const noexcept;
//int getValue() const noexcept(true);

// noexceptは参照修飾と後置戻り値型の間
auto getString() const & noexcept -> std::string;
};
```
* noexcept[color ff0000]
- `noexcept`もしくは`noexcept(trueに評価される整数定数式)`が指定された関数が例外を送出した場合、[`std::terminate()`](/reference/exception/terminate.md)関数を呼び出してプログラムを異常終了させる。その際、[`std::terminate()`](/reference/exception/terminate.md)関数が呼び出される前に、スタックの巻き戻しは起こらない可能性がある。
- 従来の`throw`キーワードによる例外仕様(C++03ではexception specification、C++11ではdynamic exception specificationと呼ばれる仕様)は、C++11以降で非推奨である。
- `noexcept`の指定可能な位置は、[参照修飾](/lang/cpp11/ref_qualifier_for_this.md)の後、[戻り値の型を後置する関数宣言構文](/lang/cpp11/trailing_return_types.md)の前である。
### 式が例外を送出する可能性があるか判定するnoexcept演算子
- 演算子としての`noexcept`は、引数として指定した定数式が例外を送出する可能性があるかどうかをコンパイル時に判定し、`bool`型の定数値を返す
Expand Down

0 comments on commit 3744030

Please sign in to comment.