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

**Code:** `expected unqualified-id before` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

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.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/expected-unqualified-id)
