https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87584
Bug ID: 87584 Summary: [8 regression] const overload ignored on operator[] in captured by value object in template function Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlegg at feralinteractive dot com Target Milestone: --- The following c++ code incorrectly produces the error "passing ‘const C’ as ‘this’ argument discards qualifiers", instead of using the C::operator[](int) const overload: struct C { int operator[](int) { return 0; } int operator[](int) const { return 1; } }; template <typename T> int f(T) { C c; return [=] { return c[0]; }(); } int main() { return f(0); } The bug reproduces on GCC 8.1 and 8.2. However, this is handled correctly by GCC 7.3.