Fix 'Passing const as this Argument Discards Qualifiers' in C++ — Const Objects, Const References, and Const Methods
A member call is also a call on the object itself: the object becomes the implicit this argument. If that object is const — declared const, reached through a const reference or pointer, or viewed from inside a const method — only const member functions may be called on it. Read which path made the object const and the fix follows: qualify the method, or change the path that promised not to modify it.
Written November 21, 2026 · Tested with GCC 13.3.0 · 12 min read
- The rule in one paragraph
- The first failure: a non-const method on a const object
- The second failure: the same call through a const reference
- The third failure: a const method calling a non-const helper
Written November 21, 2026
Tested with GCC 13.3.0
What this guide is
Every non-static member function takes an implicit object argument: the object the call was made on, available inside the function as this. A member function declared without const after its parameter list expects that object to be non-const — its this has type Counter*, for a class Counter, and the function is allowed to modify the object through it. A member function declared int get() const expects the opposite: inside it, this has type const Counter*, only other const member functions may be called normally, and non-mutable members may not be assigned.
The error in this guide is the mismatch between those two expectations at a call site. The call offers an object whose type is const-qualified — a const Counter, a const Counter&, a const Counter*, or *this inside a const method — to a function whose implicit parameter is a non-const Counter. Accepting the call would discard the const qualifier from the object argument, and no implicit conversion may do that. GCC therefore reports passing 'const Counter' as 'this' argument discards qualifiers and adds one note pointing at the member function that was called. That note is the diagnosis: the member function, not the argument written in the source, is the declaration whose qualifier does not match.
Three different source shapes produce the same line, and this guide covers all three because the honest fix differs between them. A const object calling a reading method needs the method qualified. A helper function that takes its argument by const& — the common real-world shape, because the object only became const at the function boundary, not where it was created — needs the same method qualified, not a change at the original call site. And a const method that calls a non-const helper has the mismatch inside the class, where the fix is to qualify the helper, to make genuinely internal state mutable, or to admit the outer method is not const at all. In every shape the question is the same: does this function actually modify the object? The qualifier is where the answer is written.
Build every program in this guide with g++ -std=c++20 -g.
The rule in one paragraph
A non-static member function can be declared with a const, volatile, or const volatile qualifier after its name, and differently qualified functions have different types. In the body of a cv-qualified function, the this pointer is cv-qualified in the same way, so in a const member function only other const member functions may be called normally. The mirror image holds at call sites outside the class: a const object is an object whose type is const-qualified, or a non-mutable subobject of one, and such an object cannot be modified — a direct attempt is a compile-time error, and an indirect attempt through a reference or pointer to non-const type is undefined behavior if it is ever executed. Calling a non-const member function is a potential modification, so it falls under the same ban. Non-const objects face no restriction: they may call const and non-const member functions alike, which is why adding const to a method that does not modify anything can only widen where that method may be called, never narrow it.
The first failure: a non-const method on a const object
The smallest useful failing program declares the object itself const and calls a method that only reads:
#include <iostream>
struct Counter {
int value = 42;
int get() { return value; }
};
int main() {
const Counter c;
std::cout << c.get() << '\n';
return 0;
}
$ g++ -std=c++20 -g -o direct direct.cpp
direct.cpp: In function ‘int main()’:
direct.cpp:10:23: error: passing ‘const Counter’ as ‘this’ argument discards qualifiers [-fpermissive]
10 | std::cout << c.get() << '\n';
| ~~~~~^~
direct.cpp:5:9: note: in call to ‘int Counter::get()’
5 | int get() { return value; }
| ^~~
Read the error in its named parts. The thing being passed is 'const Counter': the expression c has that type because c was declared const, and in a member call the object expression supplies the implicit this argument — c.get() is, for type-checking purposes, a call whose first argument is c itself. The verb is discards qualifiers: binding that argument to get()'s implicit parameter, which is a non-const Counter, would strip the const away. And the note underneath names the receiving declaration, int Counter::get(), with its caret under get — the declaration that is missing the qualifier the call requires.
Nothing in the body of get() modifies the object: it reads value and returns it. The function is a reading function spelled as a modifying one, and the const object at the call site is simply the first caller honest enough to expose the spelling. This is the most common cause of the error in real code, and it is why the error so often appears far from the change that caused it: a variable is made const, or a new caller arrives holding the object as const, and every unqualified reading method on the class fails at once, one error per call. The fix is not at any of those call sites. It is in the class: every method that does not modify the object's observable state gets const after its parameter list, and the whole family of errors disappears together.
Note the [-fpermissive] tag at the end of the error line. It marks a diagnostic that a permissive compiler mode could downgrade; it is not a suggestion to use that mode. Compiling with -fpermissive would let this call through by discarding the qualifier the program itself declared, which removes the protection without removing the mismatch — the next const caller, and every reader of the class, still cannot tell which methods modify the object. Fix the declaration, not the compiler's strictness.
The second failure: the same call through a const reference
In real code the object is rarely declared const where it is created. It becomes const at a function boundary, when a function that only reads its argument takes that argument by const reference — and then discovers it cannot call the argument's own reading methods:
#include <iostream>
struct Counter {
int value = 42;
int get() { return value; }
};
void print_value(const Counter& counter) {
std::cout << "value = " << counter.get() << '\n';
}
int main() {
Counter c;
print_value(c);
return 0;
}
$ g++ -std=c++20 -g -o through through.cpp
through.cpp: In function ‘void print_value(const Counter&)’:
through.cpp:9:43: error: passing ‘const Counter’ as ‘this’ argument discards qualifiers [-fpermissive]
9 | std::cout << "value = " << counter.get() << '\n';
| ~~~~~~~~~~~^~
through.cpp:5:9: note: in call to ‘int Counter::get()’
5 | int get() { return value; }
| ^~~
The object in main is not const at all: Counter c; is an ordinary modifiable variable, and passing it to a const Counter& parameter is an ordinary, always-legal binding — a reference to const may bind to a non-const object. Inside print_value, however, the only name for that object is the parameter counter, whose type is const Counter&. Through that name the object is const, so counter.get() offers a const Counter as the this argument and fails with exactly the first program's error, at a line where no const object was ever declared. The header line of the diagnostic gives this away: it names void print_value(const Counter&), not main — the failure lives in the function that holds the const view, not in the caller that handed over a mutable object.
This shape explains the error's reputation for appearing in code that "has no const objects in it." The const is in a parameter type, a pointer type such as const Counter*, or a const method's this — any access path that views the object as const is enough, because the check is on the type of the expression used to make the call, not on how the underlying object was originally declared. It also explains why the wrong fix is so tempting here: changing print_value to take Counter& makes this program compile, and for a function that genuinely only prints, it is a downgrade disguised as a fix. A Counter& parameter refuses const arguments, refuses temporaries, and tells every future caller that the function may modify what it is given. The reading method was the declaration at fault — the note points at Counter::get(), not at the parameter — and qualifying get() fixes this call while keeping print_value's honest read-only signature, as the fixed program below shows.
The general rule for this shape: when the error line sits inside a function whose parameter is a const reference or a pointer to const, do not edit that parameter until you have read the note. If the note's member function does not modify its object, the member function gets the qualifier. The parameter changes only when the function containing it really does need to modify the argument — and then the modification, not the printing, is what the new signature should be understood as advertising.
The third failure: a const method calling a non-const helper
The third shape never leaves the class. A method is correctly qualified const, and inside it, this is a pointer to const — so a call to an unqualified helper on the same object offers that const this to a function that expects a non-const one:
#include <iostream>
struct Meter {
int value = 42;
int accesses = 0;
int get() const {
note_access();
return value;
}
void note_access() { ++accesses; }
};
int main() {
Meter m;
std::cout << m.get() << '\n';
return 0;
}
$ g++ -std=c++20 -g -o inside inside.cpp
inside.cpp: In member function ‘int Meter::get() const’:
inside.cpp:7:20: error: passing ‘const Meter’ as ‘this’ argument discards qualifiers [-fpermissive]
7 | note_access();
| ~~~~~~~~~~~^~
inside.cpp:10:10: note: in call to ‘void Meter::note_access()’
10 | void note_access() { ++accesses; }
| ^~~~~~~~~~~
The call site, note_access();, names no object at all, which is what makes this shape the hardest to read the first time. An unqualified member call inside a member function is a call on *this, so the object argument is *this — and because get() is a const member function, this has type const Meter* and *this is a const Meter. The header line states exactly that context: In member function 'int Meter::get() const'. The note then points at the helper, void Meter::note_access(), which is unqualified and therefore expects a non-const object. Same error, same structure: a const object argument, a non-const implicit parameter, a discarded qualifier.
Here, unlike the first two shapes, qualifying the helper is not by itself enough — and the reason is visible in the helper's body. note_access() increments accesses, and inside a const member function a non-mutable member may not be assigned at all, so a const-qualified note_access() that still increments accesses would fail with a different error, about assignment in a read-only context. The class has a genuine design question to answer, and the compiler is asking it precisely: is the access count part of the object's observable state, or is it internal bookkeeping that a reading operation may update without changing what the object means? If the count is observable state — if two objects with different counts are different values — then get() is not a const operation in any honest sense, and the fix is to remove const from get() and accept that const objects cannot call it. If the count is bookkeeping — a cache, a counter kept for instrumentation, a lock, state that does not affect the externally visible state of the class — the language has a specific spelling for exactly that member, and the fixed program uses it.
That spelling is mutable. A member declared mutable may be modified even if the containing object is declared const: it is exempt from the object's constness, and it may therefore be assigned inside const member functions. The specifier is restricted to non-static data members of non-reference, non-const type — it cannot rescue a reference member or a member that is itself const — and its intended use is narrow: members that do not affect the externally visible state of the class, such as mutexes, memo caches, lazy evaluation state, and access instrumentation. An access counter is the textbook member of that list. What mutable must not become is a blanket applied to every member that ever trips this error: a mutable member is modifiable through every const object and every const reference the program ever creates, so marking the object's real value mutable would not fix the design — it would repeal const for that member everywhere.
Reading any discards-qualifiers output: a short procedure
Whatever the shape, the output has the same grammar, and this order of reading extracts the fix fastest:
- Read the type named after
passing— it is the type of the object expression at the call, including theconstthat triggered the error. Then find where that const came from: a const declaration at the call site, a const reference or pointer-to-const parameter, or a const method's ownthis. That origin tells you which of the three shapes you are in. - Read the
note:line before editing anything. It points at the member function declaration whose implicit parameter could not accept the const object. That declaration, not the call site, is where the qualifier is missing — or, if that function genuinely modifies the object, it is the proof that the call site's const view is the thing that has to change. - Decide, from the member function's body, whether it modifies the object's observable state. A body that only reads settles the question: qualify the function
const. A body that writes settles it the other way: the function stays non-const, and the caller must present a non-const object. - If the writing body is called from inside a const method, separate the members it writes into observable state and internal state before choosing. Observable state written from a const method means the outer method is misqualified. Internal state only — a cache, a counter, a mutex — means those specific members are candidates for
mutable, and the helper that writes only them can then be qualifiedconstas well.
The fixed program: one qualifier per failure
The fixed program qualifies the reading method const, qualifies its helper const as well, marks only the access counter mutable, keeps the const-reference printing function exactly as it was, and adds one function that takes a non-const reference because mutation is its whole purpose:
#include <iostream>
struct Counter {
int value = 42;
mutable int accesses = 0;
int get() const {
note_access();
return value;
}
void note_access() const { ++accesses; }
void set(int new_value) { value = new_value; }
};
void print_value(const Counter& counter) {
std::cout << "value = " << counter.get() << '\n';
}
void reset(Counter& counter) {
counter.set(0);
}
int main() {
const Counter c;
std::cout << "const object = " << c.get() << '\n';
std::cout << "accesses = " << c.accesses << '\n';
Counter d;
print_value(d);
Counter e;
e.set(7);
reset(e);
print_value(e);
return 0;
}
$ g++ -std=c++20 -g -o fixed fixed.cpp
$ ./fixed
const object = 42
accesses = 1
value = 42
value = 0
Read the four output lines against the three failures. const object = 42 is the first failure discharged: c is still declared const, and get() — now int get() const — accepts a const object because its this is a pointer to const. accesses = 1 is the third failure's evidence: that one call to get() ran note_access(), now also const, which incremented accesses — legal, on a const object, only because accesses is declared mutable; value, which is not mutable, remains unassignable from any const context in the program. value = 42 is the second failure discharged with no change to its function: print_value still takes const Counter&, and it can now call get() through that reference because get() is const. value = 0 is the mutation path done honestly: e is set to 7, then reset — which takes a plain Counter&, because changing the object is its point — calls the still-non-const set(0), and the final print through a const reference reads the result back. Note what reset cannot be given: the const object c would fail as its argument, with a binding error rather than this guide's error, because a non-const reference may not bind to a const object at all. That refusal is the system working as designed in both directions.
The fixes, ranked
Make the method const when it does not modify the object. Ranked first because it is the fix the majority of real occurrences need, and the only one that repairs every failing call site at once: const objects, const references, pointers to const, and const methods calling the method all start working, while existing non-const callers are unaffected, since a non-const object may call a const member function. The qualifier goes after the parameter list, in both the declaration and any out-of-line definition: int get() const. Check the body before applying it — a body that assigns a non-mutable member or calls a non-const member will fail inside the newly qualified method, and that new failure is information about the next member or helper that needs the same decision, as the third failure showed.
Take a non-const reference when mutation is the point. If the function — member or free — genuinely must modify the object, the const at the call site is the error's real subject: the caller promised the object would not change and then asked for a change. Change the promise, not the method: declare the object non-const, or change the parameter from const T& to T&, accepting what that signature then advertises and what it refuses — temporaries and const objects will no longer bind, which is correct, because their modified state could never be read back or was promised immutable. reset(Counter&) in the fixed program is this fix in its proper place: one clearly named mutating function, instead of a read-only-looking signature that modifies.
Use mutable only for a member that is not part of the object's visible state. A cache of a value the method could recompute, a counter kept for instrumentation, a mutex guarding the real state: these may change during a logically read-only operation, and mutable is the spelling that says so, member by member. It is ranked third because it is a per-member exemption from const, not a general fix — it applies only to non-static, non-reference, non-const members, and every member it touches becomes writable through every const view of the object in the program. If applying it to a member would surprise a reader holding a const reference, the member is observable state and does not qualify.
Treat const_cast as a last resort, and only when the underlying object is not actually const. const_cast is the one cast that may cast away constness, converting a pointer or reference to const into the corresponding non-const form referring to the same object. It has one legitimate everyday use in this area: calling an old, non-const-qualified API with an object that was declared non-const and is merely being viewed through a const path, where the API is known not to modify it, or known to modify it only in ways the object's owner accepts. Its limit is absolute: forming the non-const pointer or reference is legal, but modifying a const object through that non-const access path is undefined behavior. So const_cast on an object that was itself declared const — the const Counter c; of the first failure — buys nothing: the cast compiles, the call compiles, and any modification through it is undefined. It also fixes nothing in the class: the next const caller hits the same error, and the declaration still does not say which methods modify the object. When the choice is between qualifying a method you control and casting at its call sites, qualify the method.
Which fix for which shape
| What the output shows | Cause | Fix |
|---|---|---|
Error at a call on a variable declared const, note points at a reading method |
The method that only reads is not declared const, so its this parameter is non-const |
Declare the method const: int get() const |
Error inside a function taking const T& or const T*, on an object that was non-const in the caller |
Through the const parameter the object is a const T, and the method called on it is not const |
Declare the called method const; change the parameter to T& only if that function must modify the argument |
Error inside a const method, note points at a helper on the same object |
Inside a const method this is a pointer to const, and the helper expects a non-const object |
Declare the helper const if it only reads; if it writes only internal state, mark that state mutable first |
Error inside a const method whose helper writes the object's real value |
The outer method modifies observable state and is not honestly a const operation | Remove const from the outer method; const objects and const references then cannot call it |
| The method genuinely modifies, and the caller holds the object as const | The caller's const view and the requested modification contradict each other | Present a non-const object or a non-const reference at that call — or reconsider whether the modification should happen there at all |
Checklist
- In a member call, the object is an argument: read
obj.method()as passingobjas the implicitthisargument, with all of its qualifiers attached. - Find where the const came from before editing — a const declaration, a const reference or pointer parameter, or a const method's
this— because the three origins are fixed in three different places. - Let the note choose the first edit: it points at the member function whose qualifier does not match, and that declaration is guilty until its body proves it modifies the object.
- Qualify every method that does not modify observable state
const— a non-const object can call const methods, so qualifying a reading method never breaks an existing non-const caller. - Keep mutating operations visibly mutating: a non-const method, or a free function taking
T&, so that const objects and const references refuse them at the binding or the call. - Reserve
mutablefor members a reader holding a const reference would agree are not the object's value — caches, counters, mutexes — never for the value itself. - Never reach for
-fpermissiveor aconst_castto silence this error on an object that is actually const: the first hides the mismatch for one translation unit, and modifying a const object through a cast-away pointer or reference is undefined behavior.
Related guides on this site
- Fix 'Cannot Bind Non-const Lvalue Reference to an Rvalue' in C++ — Temporaries, Function Arguments, and const& — the binding side of the same const contract: there a non-const reference refuses a temporary at the binding, here a const object refuses a non-const method at the call.
- Fix 'No Matching Function for Call' in C++ — Reading GCC's Candidate List, Viable vs Not Viable, and Conversion Failures — the neighbouring diagnostic family, where candidates are rejected for conversion and arity reasons rather than for a discarded qualifier on the implicit object argument.
- C++ Functions: Parameters, Overloads, and Default Arguments — the groundwork on parameters and reference parameters: what a
const¶meter promises, and how a reference parameter decides whether a function can change the caller's variable.
Sources
- cppreference, Non-static member functions — for a non-static member function being declarable with a const, volatile, or const volatile qualifier after its name, for differently cv-qualified functions having different types, for the this pointer being cv-qualified in the body of a cv-qualified function, and for only other const member functions being callable normally in a const member function, with a non-const member function still callable if const_cast is applied.
- cppreference, cv (const and volatile) type qualifiers — for a const object being an object whose type is const-qualified or a non-mutable subobject of a const object, for such an object not being modifiable (a direct attempt being a compile-time error and an indirect attempt through a reference or pointer to non-const type being undefined behavior), for the mutable specifier permitting modification of a member even if the containing object is declared const and applying only to non-static members of non-reference non-const type, for mutable being used for members that do not affect the externally visible state of the class such as mutexes, memo caches, lazy evaluation, and access instrumentation, and for a conversion from a reference or pointer to a cv-qualified type to a less cv-qualified type requiring const_cast.
- cppreference, const_cast conversion — for const_cast converting between types that differ only in cv-qualification, for only const_cast being usable to cast away constness, for the result referring to the original object, and for modifying a const object through a non-const access path resulting in undefined behavior.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.