Skip to content

Commit

Permalink
fix: 宣言の遅延がされるのではなく単に失敗を無視するという仕様であった
Browse files Browse the repository at this point in the history
  • Loading branch information
yumetodo committed Mar 20, 2024
1 parent 39695e1 commit 828812e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lang/cpp17/if_constexpr.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main()

### `static_assert`文に関する例外

後に述べる2段階名前探索に関する注意点とは関係なく、C++23以降、もしくはCWG 2518が適用された環境においては、template文(もしくは適切な特殊化や`constexpr if`文の中の文)が実際にインスタンス化されるまで`static_assert`文の宣言は遅延される
後に述べる2段階名前探索に関する注意点とは関係なく、C++23以降、もしくはCWG 2518が適用された環境においては、template文(もしくは適切な特殊化や`constexpr if`文の中の文)が実際にインスタンス化されない限り`static_assert`宣言による失敗は無視される

```cpp example
#include <cstdint>
Expand All @@ -109,8 +109,8 @@ void f(T t) {

void g(std::int8_t c) {
std::int32_t n = 0;
f(n); // OK: nはstd::int32_t型なので`use(t);`のほうがインスタンス化されるために、static_assert文は宣言されない
f(c); // error: cはstd::int8_t型なので、static_assert文は宣言され、"must be 32bit"とコンパイラが診断メッセージを出力する
f(n); // OK: nはstd::int32_t型なので`use(t);`のほうがインスタンス化されるために、static_assert宣言の失敗は無視される
f(c); // error: cはstd::int8_t型なので、static_assert宣言は失敗し、"must be 32bit"とコンパイラが診断メッセージを出力する
}
```
Expand Down

0 comments on commit 828812e

Please sign in to comment.