https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89831

            Bug ID: 89831
           Summary: passing 'const ...' as 'this' argument discards
                    qualifiers
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lumosimann at gmail dot com
  Target Milestone: ---

Starting from GCC 8.1, the following code does not compile anymore:

```
struct Q { 
    int operator[](int i) { return 0; }
    int operator[](int i) const { return 0; }
};

struct Base {
    Q x;
};
struct X : public Base {
    template <typename T>
    void f(T) const {
        auto q = Base::x[0];
    }   
};
int main() { X{}.f(3); }
```

https://godbolt.org/z/UefNCx

- using `operator()` instead of `operator[]` fixes the problem
- using `x[0]` instead of `Base::x[0]` fixes the problem
- removing the template from `X::f` fixes the problem


In older versions and with clang, compilation is okay.

Reply via email to