File tree 1 file changed +2
-26
lines changed
1 file changed +2
-26
lines changed Original file line number Diff line number Diff line change @@ -116,33 +116,9 @@ void g(std::int8_t c) {
116
116
117
117
### 2段階名前探索における注意点
118
118
119
- `constexpr if`文で、実行されない方の`statement`は廃棄文(discarded statement)となり、文の実体化を防ぐ。言い換えると、2段階名前探索における依存名(dependent name)は、廃棄文の場合検証されない。また文が実体化されないのだから通常のif文と同じくもちろん実行時に実行もされない。つまり次の例は意図と異なる挙動を示す。
119
+ `constexpr if`文で、実行されない方の`statement`は廃棄文(discarded statement)となり、文の実体化を防ぐ。言い換えると、2段階名前探索における依存名(dependent name)は、廃棄文の場合検証されない。また文が実体化されないのだから通常のif文と同じくもちろん実行時に実行もされない。
120
120
121
- ```cpp
122
- template<bool> struct inferior_static_assert_failure;
123
- template<> struct inferior_static_assert_failure<true>{ enum { value = 1 }; };
124
- #define INFERIOR_STATIC_ASSERT(B) typedef char inferior_static_assert[sizeof(inferior_static_assert_failure<bool(B)>::value)]
125
- #include <type_traits>
126
-
127
- template <typename T>
128
- void f(T)
129
- {
130
- if constexpr (std::is_same_v<T, int>)
131
- {
132
- // Tがintのときのみ評価されてほしい
133
- // 実際は常に評価される
134
- INFERIOR_STATIC_ASSERT(false);
135
- }
136
- }
137
-
138
- int main()
139
- {
140
- f(2.4);
141
- f(3);
142
- }
143
- ```
144
-
145
- CWG 2518が適用されていない環境においては` static_assert ` でも同じ現象が発生する。
121
+ CWG 2518が適用されていない環境においては`static_assert`を用いる時に直感的ではない挙動を示していた。
146
122
147
123
```cpp example
148
124
#include <type_traits>
You can’t perform that action at this time.
0 commit comments