C++
Void Value Not Ignored Fix
A function declared to return void hands back nothing, so there is no value to store, print, or compute with. When GCC answers 'void value not ignored as it ought to be', the call site asked for a result the function never promised. This guide reads the diagnostic, separates the nearby mistakes that draw different errors, and fixes the call by deciding which side is wrong: the function that should return a value, or the call site that should stop asking for one.
Written November 28, 2026 · Tested with GCC 13.3.0 · 4 min read
- The failure: storing a result that does not exist
- Why auto does not dodge it
- Using the call in arithmetic draws a different error
- Passing the call as an argument draws a third error
Written November 28, 2026
Tested with GCC 13.3.0
What this guide is
The type void is the type with an empty set of values. It is an incomplete type that cannot be completed, and objects of type void are not allowed. A function declared with void as its return type is a procedure: it runs for its effect, and it hands nothing back to the caller. The call expression still has a type, and that type is void, so any code that tries to store the result, add it to a number, pass it as an argument, or print it is asking for a value that does not exist.
GCC does not use one error for all of those asks. The wording in this guide's title belongs to one specific ask: storing the call result in a variable of a real type. The nearby asks draw different diagnostics, and the middle of this guide walks through them, because the fix differs by ask. In every case the underlying fact is the same, and the repair is a decision about intent. Either the caller needs a value, in which case the function has to produce and return one, or the caller needs only the effect, in which case the call stands alone as a statement and nothing is stored.
Build every program in this guide with g++ -std=c++20 -g.
The failure: storing a result that does not exist
A logging function that prints a line and returns nothing is the usual source of this error. The function does its work; the mistake is in main, which stores the call in an int as if a status code had come back:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
}
int main() {
int status = log_ready();
std::cout << status << "\n";
return 0;
}
$ g++ -std=c++20 -g -o assign assign.cpp
assign.cpp: In function 'int main()':
assign.cpp:8:27: error: void value not ignored as it ought to be
8 | int status = log_ready();
| ~~~~~~~~~^~
Read the error in its parts. The wording is fixed: void value not ignored as it ought to be. The caret span sits under the whole call, log_ready(), not under the variable and not under the function definition. GCC is not complaining about the function, which is a legal procedure, and it is not complaining about the variable's type in isolation. It is complaining about the meeting point: an int needs a value to hold, and the call supplies none. The phrase "not ignored" is the tell. A void result may be discarded, and discarding it is the normal way to call a procedure. What it may not do is flow into a variable.
Which side is wrong depends on what the stored value was for. If the code after this line reads status to decide something, the function was supposed to report an outcome and its void return type is the bug. If nothing later reads status for a real decision, the variable is the bug: the call was written in the shape of a value-producing call out of habit, and the fix is to call the function as a statement. Both fixes appear at the end of this guide, after the nearby errors, because picking between them is easier once the other wordings are out of the way.
Why auto does not dodge it
Switching the variable to auto looks like a way to let the compiler sort it out. It does not work, and it draws a different error:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
}
int main() {
auto status = log_ready();
std::cout << status << "\n";
return 0;
}
$ g++ -std=c++20 -g -o auto-deduce auto-deduce.cpp
auto-deduce.cpp: In function 'int main()':
auto-deduce.cpp:8:10: error: deduced type 'void' for 'status' is incomplete
8 | auto status = log_ready();
| ^~~~~~
The deduced type for status would be void, and void cannot name the type of a variable, because objects of type void are disallowed. So the error moves from the assignment to the deduction: deduced type 'void' for 'status' is incomplete. The word incomplete is the same fact from the other side. A type with no values cannot be the type of a stored object, no matter whether the programmer writes the type out or asks the compiler to deduce it. When this wording appears instead of the title error, the cause is identical: a void call is being stored.
Using the call in arithmetic draws a different error
Adding the call to a number is a second way to ask for the missing value, and GCC names it differently:
#include <iostream>
void bump() {
std::cout << "bumped\n";
}
int main() {
int total = bump() + 1;
std::cout << total << "\n";
return 0;
}
$ g++ -std=c++20 -g -o arithmetic arithmetic.cpp
arithmetic.cpp: In function 'int main()':
arithmetic.cpp:8:24: error: invalid operands of types 'void' and 'int' to binary 'operator+'
8 | int total = bump() + 1;
| ~~~~~~ ^ ~
| | |
| void int
Here the diagnostic is about the operator: invalid operands of types 'void' and 'int' to binary 'operator+', with the two operand types spelled out under the expression, void on the left and int on the right. The reading is literal. The plus operator needs two values; the left one has type void, which has no values. This wording means the same decision as the title error, reached from a different ask: either bump returns a count worth adding, or the addition goes away and the call stands alone.
Passing the call as an argument draws a third error
Feeding the call into another function as an argument is a third ask, with a third wording:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
}
void report(int value) {
std::cout << value << "\n";
}
int main() {
report(log_ready());
return 0;
}
$ g++ -std=c++20 -g -o argument argument.cpp
argument.cpp: In function 'int main()':
argument.cpp:12:21: error: invalid use of void expression
12 | report(log_ready());
| ~~~~~~~~~^~
The error is invalid use of void expression, and the caret span again covers the whole inner call. report needs an int argument; the argument expression has type void. This is the wording to expect whenever a void call sits where an argument value is required, including inside a larger expression that a function call is part of. The fix follows the same fork: give the inner function a return value to pass, or call it separately for its effect and pass a real value to the outer function.
A conditional branch of type void draws a fourth error
A conditional expression has to produce one type from its two branches. When one branch is a void call and the other returns an int, GCC rejects the mix:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
}
int fallback() {
return 0;
}
int main() {
bool ok = true;
int status = ok ? log_ready() : fallback();
std::cout << status << "\n";
return 0;
}
$ g++ -std=c++20 -g -o conditional conditional.cpp
conditional.cpp: In function 'int main()':
conditional.cpp:13:45: error: second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
13 | int status = ok ? log_ready() : fallback();
| ~~~~~~~~^~
The wording names the exact problem: the second operand is of type void, but the third operand is neither a throw-expression nor of type void. A conditional whose branches are both void is legal and simply runs one of the two calls. A conditional with one void branch and one value branch has no single type, so it cannot initialize an int. When this error appears, the intent is usually that both branches produce the status, which means the void function is the side that has to change.
The mirror mistake: returning a value from a void function
The reverse confusion produces its own error, inside the function rather than at the call site:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
return 1;
}
int main() {
log_ready();
return 0;
}
$ g++ -std=c++20 -g -o return-value return-value.cpp
return-value.cpp: In function 'void log_ready()':
return-value.cpp:5:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
5 | return 1;
| ^
The wording is return-statement with a value, in function returning 'void'. A return statement with an expression is disallowed in a function whose return type is void, unless the expression itself has type void. That exception is real, and it is the one place a void call can legally be returned:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
}
void run() {
return log_ready();
}
int main() {
run();
return 0;
}
$ g++ -std=c++20 -g -o return-void-call return-void-call.cpp
$ ./return-void-call
ready
run is a void function, and return log_ready(); compiles, because the returned expression has type void. The call runs, prints its line, and run returns. This form is common in forwarding functions that hand control to another procedure. It also marks the boundary of the title error: a void expression may be returned from a void function, and it may be discarded, as a statement or anywhere a value is thrown away. Every use that needs a value fails, because the expression does not have one.
Fix one: make the function return the value
When the caller genuinely needs the result, the function changes. Give it a return type, return a value on the path the caller cares about, and the original call site compiles unchanged:
#include <iostream>
int log_ready() {
std::cout << "ready\n";
return 1;
}
int main() {
int status = log_ready();
std::cout << status << "\n";
return 0;
}
$ g++ -std=c++20 -g -o fixed-return fixed-return.cpp
$ ./fixed-return
ready
1
The run shows both lines: the function still prints ready, and the stored status now prints as 1. Changing the return type is an interface change, so every caller of the function has to be checked. Callers that called it as a statement are unaffected in behavior, because a returned value may always be discarded. Callers that stored the result in a different type may now convert the new return value in ways worth reading once. The signature change is small; the audit of its call sites is the real work.
Fix two: call it for its effect only
When nothing needs the value, the call site changes and the function does not. Delete the variable, keep the call as a statement:
#include <iostream>
void log_ready() {
std::cout << "ready\n";
}
int main() {
log_ready();
return 0;
}
$ g++ -std=c++20 -g -o fixed-call-only fixed-call-only.cpp
$ ./fixed-call-only
ready
The output is the single line the function exists to print. This is the smaller fix, and it is the right one whenever the stored variable was never read, or was read only to be printed for want of anything better to do with it. If a later line does need an outcome from the function, that need is the signal to use fix one instead, and to have the function return the specific outcome that line decides on, rather than a generic code invented at the call site.
The fixes, ranked
- Call the function as a statement when nothing needs a value. One line changes, the interface does not, and the error is gone.
- Change the function to return the value when a caller needs to decide on it. Audit every call site after the signature change.
- Never paper over the error by inventing a placeholder value at the call site. The placeholder compiles, but it hides the missing decision the compiler just found, and every later read of the variable acts on a value the function never reported. Casting the call to void first does not rescue the store either: the cast result is still void, and storing it draws the same title error.
Checklist
- Read the caret span: the title error sits under the call whose result is being stored.
- Name the ask: storing, deducing with auto, arithmetic, an argument, and a conditional branch each draw a different wording for the same missing value.
- Decide which side is wrong before editing: the function's return type, or the call site's variable.
- Remember the legal uses of a void expression: discard it, or return it from a function whose return type is void. Any use that needs a value fails.
- After changing a return type, read every call site of the function once.
Related guides on this site
- C++ Invalid Types Array Subscript Fix
- C++ Return Value in Void Fix
- 'std::unique' Is Not a Member of 'std' Fix
- 'std::search_n' Is Not a Member of 'std' Fix
Sources
- cppreference, Fundamental types — void is the type with an empty set of values, an incomplete type that cannot be completed, and objects of type void are disallowed; functions returning void are permitted.
- cppreference, Return statement — the return expression is optional in functions whose return type is void, and in a function returning void a return statement with an expression can be used when the expression type is void.
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.