llvm / llvm/llvm-project

SFINAE fails inside generic lambdas

Open
#189,439 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This should compile fine, but doesn't: https://godbolt.org/z/W93PdeW91
```c++
#include
#include

template
struct HasFoo : std::false_type {};

template
struct HasFoo<
C, T, decltype((void)(*std::declval().foo() = std::declval()))> : std::true_type {};

template
void call_foo(C& c) {
[&](auto&& value) {
using T = decltype(value);
if constexpr (HasFoo::value) {
*c.foo() = std::forward(value);
}
};
}

int main() { call_foo(""); }
```
```
:16:9: error: member reference base type 'const char[1]' is not a structure or union
16 | *c.foo() = std::forward(value);
| ~^~~~
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the linked Godbolt reproducer and compare the generic-lambda and SFINAE behavior shown in the issue. Trace how the compiler handles the HasFoo check and the if constexpr branch for the const char array; done means the reproducer compiles without the reported member-reference error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.