https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104995
Bug ID: 104995
Summary: access checking for function pointer template
parameters takes place at call site
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mawww at kakoune dot org
Target Milestone: ---
The following code
```
template<auto F>
void func() {
auto lambda = [&](auto&& s) { F(s); };
lambda(0);
}
struct S {
void f() { func<S::g>(); }
private:
static void g(int) {}
};
```
Fails to compile on g++ 11.2.1 with the following error:
```
test.cc: In instantiation of ‘func<S::g>()::<lambda(auto:1&&)> [with auto:1 =
int]’:
test.cc:4:11: required from ‘void func() [with auto F = S::g]’
test.cc:8:26: required from here
test.cc:3:36: error: ‘static void S::g(int)’ is private within this context
3 | auto lambda = [&](auto&& s) { F(s); };
| ~^~~
test.cc:11:17: note: declared private here
11 | static void g(int) {}
| ^
```
Clang accepts this code, making func's body just `{ F(0); }` compiles without
errors as well.