-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect Clang compilation error in non-taken if-constexpr branch within template lambda #129912
Comments
@llvm/issue-subscribers-clang-frontend Author: Michael Bentley, PhD (mikebentley15)
Godbolt: https://godbolt.org/z/WGWWozG1q
The scenario is fairly strange to reproduce. It's code to conditionally wrap a callable with a mutable or a const lambda. The Simplified code: #include <cstdio>
#include <iostream>
#include <type_traits>
#include <utility>
struct ConstWrap
{};
struct MutableWrap
{};
auto lambdaWrap(auto callable) -> decltype(auto)
{
const auto decorator = [&callable]<typename WrapType>() {
if constexpr (std::is_same_v<ConstWrap, WrapType>) {
return [capturedCallable = std::move(callable)]() {
std::puts("ConstWrap");
capturedCallable();
};
} else {
return [capturedCallable = std::move(callable)]() mutable {
std::puts("MutableWrap");
capturedCallable();
};
}
};
return decorator.template operator()<MutableWrap>();
}
int main()
{
auto decorated =
lambdaWrap([counter = 0]() mutable { std::cout << "Counter: " << ++counter << "\n"; });
decorated();
return 0;
} This fails with
on Clang 18.1.0 and on trunk (same error). This works if the GCC 10.4 is capable of compiling this example. Perhaps this is related to #113792. |
Godbolt: https://godbolt.org/z/WGWWozG1q
The scenario is fairly strange to reproduce. It's code to conditionally wrap a callable with a mutable or a const lambda. The
if constexpr
branch that isn't taken causes the compilation to fail.Simplified code:
This fails with
on Clang 18.1.0 and on trunk (same error). This works if the
decorator
lambda is not within a templated function (e.g., move it intomain()
and it works). My current workaround is to move theif constexpr
outside of thedecorator
.GCC 10.4 is capable of compiling this example.
Perhaps this is related to #113792.
The text was updated successfully, but these errors were encountered: