# C/C++: error: expected ';' before 'x' — missing semicolon

**Code:** `expected ';' before` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

The compiler reached a token where a statement should have ended — almost always a missing semicolon on the line above.

## Meaning

GCC and Clang report this at the next token, so the real mistake is usually one line earlier, or after the closing brace of a struct, class or enum. An unbalanced bracket or a macro that expands badly can trigger the same message.

## Common causes

- Missing `;` at the end of the previous statement
- Missing `;` after the closing `}` of a struct, class or enum
- Unbalanced `(` or `{` earlier in the file
- A macro or header that ends in the middle of a statement

## Quick fix

1. Look at the line before the one in the message
2. Add `;` after the `}` of every struct, class and enum definition
3. Fix only the first error and rebuild — the rest are often a cascade

## Detailed fix by platform

### GCC / Clang

1. Compile with warnings on to see the first real problem: `g++ -Wall -Wextra -std=c++17 -c main.cpp`
2. Read the line above the reported line and check its last character

### Editor

1. Use bracket matching (VS Code: Ctrl+Shift+\) to find an unclosed `{` or `(` above the error

## Code examples

### Missing semicolon after a struct

```cpp
struct Point {
    int x;
    int y;
}                       // <-- missing ';' here

int main() {
    Point p{1, 2};      // GCC reports the error on this line
    return p.x;
}
```

The error points at `int main`, but the fix is the `;` after the struct's closing brace.

## How to diagnose

1. **Position** — Is the mistake on the line before the reported one?
2. **Braces** — Do every `{` and `(` have a partner?
3. **Cascade** — Is this the first error in the output?

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