<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125491>125491</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
if constexpr code not ignored
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Toeger
</td>
</tr>
</table>
<pre>
### Minimal reproducible example
```cpp
template <class... Ts>
struct Type_list {
private:
template <int index, class... Args>
struct Get_at;
template <class T, class... Args>
struct Get_at<0, T, Args...> {
using Type = T;
};
template <int index, class T, class... Args>
struct Get_at<index, T, Args...> {
using Type = typename Get_at<index - 1, Args...>::Type;
};
public:
template <int index>
using at = typename Get_at<index, Ts...>::Type;
constexpr static auto size = sizeof...(Ts);
};
template <class F>
struct CI {};
template <class R, class... PArgs>
struct CI<R (*)(PArgs...)> {
using Args = Type_list<PArgs...>;
};
template <class Function>
constexpr bool is_viable_source = []<class Properties_list>(Properties_list) {
if constexpr (Properties_list::size != Properties_list::size) {
static_assert(false);
return sizeof(typename CI<Function>::Args::template at<0>) > 0;
}
return false;
}(Type_list<>{});
int main() {
return is_viable_source<void (*)()>;
}
```
https://godbolt.org/z/o3co4j31e
### Expected behavior
Successfully builds executable equivalent to `int main() {}`.
### Actual behavior: Compilation error
```
<source>:17:2: error: implicit instantiation of undefined template 'Type_list<>::Get_at<0>'
17 | using at = typename Get_at<index, Ts...>::Type;
| ^
<source>:32:55: note: in instantiation of template type alias 'at' requested here
32 | return sizeof(typename CI<Function>::Args::template at<0>) > 0;
| ^
<source>:29:78: note: while substituting into a lambda expression here
29 | constexpr bool is_viable_source = []<class Properties_list>(Properties_list) {
| ^
<source>:38:9: note: in instantiation of variable template specialization 'is_viable_source<void (*)()>' requested here
38 | return is_viable_source<void (*)()>;
| ^
<source>:5:9: note: template is declared here
5 | struct Get_at;
| ^
1 error generated.
```
### Affected versions
Clang 18, clang 19 and clang trunk
C++23 and above (it seems the explicit lambda template argument is required to reproduce, which is a C++23 feature)
Gcc compiles the code successfully.
### Reasoning why clang is wrong
The error is caused by code inside an `if constexpr` that evaluates to `false`, thus clang should not have attempted to compile the code or ignored the error. Clang partially agrees that the `if constexpr` evaluates to `false` and that the code should not be compiled since it does not complain about the `static_assert(false);`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V09v2z4S_TT0ZVBDomzLPvigOHGxhwWCbu4BJY0tdmlS5R8n6adfDCVLtuM07f5QI0Dlajjz3rzhIy2ck3uNuGbzOza_n4jgG2PXTwb3aCelqd_WjGfdH_xbankQCiy21tShkqVCwFdxaBWypGCLpPur2pYlhcdDq4RHYNmmUsK56XQKT45lDywpnLeh8vD01uKzks4Dy-8oRbJqrTwKjywruu_naaT2IHWNr4xvYMhZ2H2flSWrPvFX9M_Cs-zufZK4Dp5-O8UmodAYT2HT6ZRlDyNelqyCk3ofuQDL7uFpKMvy-5sQ3vP4EzzDyj_A5N9a1OKAV1ngC6SXSajvWUHrbrGIAoVSyeoTfU7YOxjC_wpEpPJx-cpo5_G1teC88LICEbwBJ392zOjB7Gg1Xz45xlf9wjPQ79XfXkzh5l-xdacV78O_XYjzOKozJGDZ5hswvmS8IAh8-XhqKQE6k6ZrCL3sZuW0AVi2eTxX4Tc4BF15aXSHZOxSaYwC6Z6PUpQKn50Jtupa1e3xIcGjNS1aL9H1CB4I99V_8tWIXe5gLHMjNmrXCcNTKvhhwEXaOOKk7LNwDq1nfLkTyuGoZYyx6IPVvd6ML4dpit0_70Ys04lET0Pr-t1MPFdAqiQXMx4f-iodgEEFvjwXijJ08zIiLGj2D0LqOARn7PqE14KwbHM0sr6YmW5Wxqrdjju5KkuKxvs2kuJbxrd7U5dG-amxe8a3Pxnfmqwys-9Ziv3SwbkfXlusPNZQYiOO0liWFP8JVYXO7YJSb1AGqWoH-IpV8CL6-o8gj0Kh9uANsEVyg2B-zxbJ9LpYUfkg1FgqK2BjDq1UggQCtDbWP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