https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124338
Bug ID: 124338
Summary: Inconsistent const for capture in generic lambda
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: herring at lanl dot gov
Target Milestone: ---
Given <https://godbolt.org/z/j1dcW6M59>
struct X {
int f();
int f() const;
};
void g(X x) {
[x](auto) {sizeof(x.f());}(1);
}
GCC trunk complains that "passing ‘const X’ as ‘this’ argument discards
qualifiers" because it picks the wrong overload of f. The genericity of the
lambda matters, and it must be instantiated.
This seems closely related to #122048, but it seems to have been introduced in
12.1.