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

C++: error: expected primary-expression before ')' token

The parser expected a value or expression and found a token that cannot start one — often a type name passed where a value belongs.

Exact message you may see expected primary-expression beforeexpected primary-expression before ')' tokenexpected primary-expression before 'int'expected expression
Seen on: C/C++ GCC Clang

Meaning

Typical triggers: passing a type to a function (foo(int)), an empty argument, a stray comma or ), or a macro that expands to nothing. GCC names the unexpected token in the message, so look at what precedes it.

Common causes

  • A type name used where a value is expected (for example sizeof(x) written as size(int x))
  • Missing argument between commas or before )
  • Trailing comma in an argument or initializer list
  • Macro that expands to an empty expression
  • Mixing up declaration syntax and a function call

⚡ Quick fix

  1. Check the arguments of the call at the reported column
  2. Remove stray commas and extra )
  3. Pass a variable or literal, not a type

Detailed fix by platform

GCC / Clang

  1. Expand macros to see the real code: g++ -E main.cpp | less and search near the reported line

Code examples

Type passed instead of a value

cpp
int square(int n) { return n * n; }

int main() {
    // int r = square(int);          // error: expected primary-expression before 'int'
    int r = square(5);
    return r;
}

How to diagnose

  1. Token — Which token does the message name?
  2. Arguments — Are all argument slots filled?
  3. Macros — Does a macro expand to nothing?

🔧 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 typeE0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308expected ';' before — C/C++: error: expected ';' before 'x' — missing semicolon (C/C++)expected ';' beforeexpected unqualified-id before — C++: error: expected unqualified-id before 'return' / before ')' token (C/C++)expected unqualified-…need typename before dependent name — C++: error: need 'typename' before 'T::iterator' because 'T' is a dependent scope (C/C++)need typename before …no matching function for call to — C++: error: no matching function for call to 'f(int, const char*)' (C/C++)no matching function …stray in program — C/C++: error: stray '\342' in program (smart quotes or invisible characters) (C/C++)stray in programexpected …

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.