Bug 102791 - Friend declaration of lambda function is ignored
Summary: Friend declaration of lambda function is ignored
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, rejects-valid
: 112455 (view as bug list)
Depends on:
Blocks: c++-friends, cxxfriends c++-lambda-decltype lambdas
  Show dependency treegraph
 
Reported: 2021-10-15 20:45 UTC by Fedor Chelnokov
Modified: 2024-08-21 15:08 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fedor Chelnokov 2021-10-15 20:45:39 UTC
This is a valid program:
```
constexpr auto f = [](auto& x){
    x.m();
};

class A{
    friend decltype(f);
    void m() {}
public:
    void n() {
        f(*this);
    }
};

int main(){
    A{}.n();
}
```
which is accepted by Clang and MSVC, but unfortunately not by GCC.

The error is
```
error: 'void A::m()' is private within this context
    2 |     x.m();
```
Demo: https://gcc.godbolt.org/z/vKnhqG9b1

Related discussion: https://stackoverflow.com/q/64390688/7325599
Comment 1 Andrew Pinski 2021-10-15 20:50:32 UTC
Confirmed.
Comment 2 Andrew Pinski 2023-11-09 12:48:59 UTC
*** Bug 112455 has been marked as a duplicate of this bug. ***