discards qualifiers C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive]

A const object (or const reference) is calling a method that is not declared const, which could modify it.

Exact message you may see discards qualifierspassing 'const' as 'this' argument discards qualifierserror: binding reference of type to discards qualifierscannot bind non-const lvalue referenceno viable function (candidate function not viable: 'this' argument has type 'const
Seen on: C/C++ GCC Clang

Meaning

Calling obj.method() on a const Obj& is only allowed if method() is marked const. Mark every method that does not change the object const; that is also what makes them usable from const references and in containers.

Common causes

  • Member function that only reads data is not declared const
  • Const reference or pointer parameter calling a non-const method
  • Range-for over a const container using non-const methods
  • operator[] or begin() without a const overload

⚡ Quick fix

  1. Add const after the parameter list: int size() const;
  2. Change T& to const T& only if the method truly does not modify
  3. Provide both const and non-const overloads when needed

Detailed fix by platform

C++

  1. Declare read-only methods as int size() const { return n_; }
  2. If it caches data, mark the cache mutable

Code examples

Make read-only methods const

cpp
struct Stack {
    int top() const { return v[n - 1]; }   // const: only reads
    void push(int x) { v[n++] = x; }       // modifies, so non-const
    int v[16]; int n = 0;
};

void print(const Stack& s) {
    s.top();          // OK
    // s.push(1);     // error: passing 'const Stack' as 'this' argument discards qualifiers
}

How to diagnose

  1. Object — Is the object const?
  2. Method — Is the called method declared const?
  3. Intent — Does the method modify state?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…incomplete type — C++: error: invalid use of incomplete type 'class X' — forward declaration only (C/C++)incomplete typeinvalid conversion from — C++: error: invalid conversion from 'const char*' to 'char*' [-fpermissive] (C/C++)invalid conversion fr…is private within this context — C++: error: 'int X::secret' is private within this context (C/C++)is private within thi…no match for 'operator' — C++: error: no match for 'operator<<' (operand types are 'std::ostream' and 'X') (C/C++)no match for 'operato…use of deleted function — C++: error: use of deleted function 'X::X(const X&)' — copying a non-copyable type (C/C++)use of deleted functi…discards …

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.