expected ';' before C/C++ Origin: Application & API Last updated 15 Oct 2026

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

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

Exact message you may see expected ';' beforeexpected ';' after struct definitionexpected ';' at end of declarationexpected ';' at end of member declarationexpected ';' after class
Seen on: C/C++ GCC Clang

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?

🔧 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 primary-expression before — C++: error: expected primary-expression before ')' token (C/C++)expected primary-expr…expected 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 …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.