expected unqualified-id before C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: expected unqualified-id before 'return' / before ')' token

The parser found a token where a name (declaration) was required — often a missing brace, a stray ), or a statement placed in a class body.

Exact message you may see expected unqualified-id beforeexpected unqualified-id before 'return'expected unqualified-id before ')' tokenexpected unqualified-id before numeric constantexpected identifier or '('
Seen on: C/C++ GCC Clang

Meaning

This is a catch-all syntax error that GCC emits when it expects an identifier. Missing } before a function, code placed directly in a class or at global scope, a stray semicolon after a function header, or a macro that swallowed a token are the common causes.

Common causes

  • Missing or extra closing brace earlier in the file
  • Executable statement written inside a class body or at file scope
  • Stray ; or ) after a function signature
  • Using a keyword or macro name as an identifier (int new;, int max with a max macro)
  • Declaration of a variable with a reserved name

⚡ Quick fix

  1. Check braces above the error with your editor's matching
  2. Move statements into a function
  3. Rename identifiers that clash with keywords or macros (define NOMINMAX on Windows)

Detailed fix by platform

GCC / Clang

  1. Compile only that file with -fsyntax-only and fix the first error; later ones usually cascade

Windows

  1. Before including <windows.h> add #define NOMINMAX so min/max are not macros

Code examples

Statement inside a class body

cpp
struct Counter {
    int n = 0;
    n++;                      // error: expected unqualified-id before '++' token
    void inc() { n++; }       // OK: statements belong in functions
};

How to diagnose

  1. Position — What comes just before the reported token?
  2. Braces — Balanced up to this point?
  3. Names — Is an identifier a keyword or macro?

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

declared and not used — Go: declared and not used: x / "fmt" imported and not used (Go)declared and not useddoes not name a type — C++: error: 'string' does not name a type (C/C++)does not name a typeexpected ';' before — C/C++: error: expected ';' before 'x' — missing semicolon (C/C++)expected ';' beforeexpected primary-expression before — C++: error: expected primary-expression before ')' token (C/C++)expected primary-expr…need typename before dependent name — C++: error: need 'typename' before 'T::iterator' because 'T' is a dependent scope (C/C++)need typename before …stray in program — C/C++: error: stray '\342' in program (smart quotes or invisible characters) (C/C++)stray in programwas not declared in this scope — C++: error: 'x' was not declared in this scope (undeclared identifier) (C/C++)was not declared in t…expected …

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.