control reaches end of non-void function C/C++ Origin: Application & API Last updated 15 Oct 2026

C/C++: warning: control reaches end of non-void function [-Wreturn-type]

A function that promises a return value can finish without returning one on some path — undefined behaviour in C++.

Exact message you may see control reaches end of non-void functionwarning: no return statement in function returning non-voidnon-void function does not return a value in all control pathsmissing return statement
Seen on: C/C++ GCC Clang

Meaning

Flowing off the end of a non-void function is undefined behaviour in C++ (the caller may use garbage, or execution may fall into the next function). It often shows up as a crash only at -O2. Return on every path, or restructure with a final return / throw.

Common causes

  • An if/else if chain without a final else return
  • A switch without a default that returns
  • Return placed only inside a loop that might not run
  • Function body missing return after a catch block

⚡ Quick fix

  1. Add a return or throw at the end of the function
  2. Treat the warning as an error with -Werror=return-type
  3. Add default: to switch statements

Detailed fix by platform

GCC / Clang

  1. Enable it explicitly: g++ -Wall -Wextra -Werror=return-type main.cpp
  2. Add [[noreturn]] to functions that never return (for example wrappers around abort)

Code examples

Missing return on one path

cpp
int sign(int x) {
    if (x > 0) return 1;
    if (x < 0) return -1;
    // warning: control reaches end of non-void function (x == 0)
    return 0;                  // fix
}

How to diagnose

  1. Paths — Which input reaches the end?
  2. Switch — Is there a default?
  3. Flags — Compiled with -Wall?

🔧 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):

C4996 — MSVC: error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead (C/C++)C4996cannot 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…comparison of integers of different signs — C/C++: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' [-Wsign-compare] (C/C++)comparison of integer…format expects argument of type — C: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=] (C/C++)format expects argume…implicit declaration of function — C: warning: implicit declaration of function 'foo' [-Wimplicit-function-declaration] (C/C++)implicit declaration …runtime error: — C/C++: runtime error: signed integer overflow / null pointer / shift exponent too large (UndefinedBehaviorSanitizer) (C/C++)runtime error:Segmentation fault — C/C++: Segmentation fault (core dumped) — SIGSEGV from a null, dangling or out-of-bounds pointer (C/C++)Segmentation faultcontrol r…

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.