-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
if constexpr code not ignored inside an immediately invoked lambda #125491
Comments
@llvm/issue-subscribers-clang-frontend Author: None (Toeger)
### 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;
};
}; template <class F> template <class Function> int main() {
<source>:17:2: error: implicit instantiation of undefined template 'Type_list<>::Get_at<0>'
|
@erichkeane do we have an issue to track "Erich needs to work on delayed body instantiation"? |
Probably... i just don't know it . EDIT: Think it is this one: #58872 Thats the one that caused me to talk about it initially. I put together a 'doesn't work at all' 1st pass patch here (https://reviews.llvm.org/D138148). I'm reasonably confident that the Phab review + "make sure we instantiate it everywhere we actually call it" would be enough to get that feature done correctly. |
Minimal reproducible example
https://godbolt.org/z/o3co4j31e
Expected behavior
Successfully builds executable equivalent to
int main() {}
.Actual behavior: Compilation error
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 tofalse
, thus clang should not have attempted to compile the code or ignored the error. Clang partially agrees that theif constexpr
evaluates tofalse
and that the code should not be compiled since it does not complain about thestatic_assert(false);
.Workaround
The code compiles after replacing the immediately invoked lambda with a helper function: https://godbolt.org/z/6P5qToWWT
This also applies to my ungolfed code.
The text was updated successfully, but these errors were encountered: