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.
expected ';' beforeexpected ';' after struct definitionexpected ';' at end of declarationexpected ';' at end of member declarationexpected ';' after class 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
- Look at the line before the one in the message
- Add
;after the}of every struct, class and enum definition - Fix only the first error and rebuild — the rest are often a cascade
Detailed fix by platform
GCC / Clang
- Compile with warnings on to see the first real problem:
g++ -Wall -Wextra -std=c++17 -c main.cpp - Read the line above the reported line and check its last character
Editor
- Use bracket matching (VS Code: Ctrl+Shift+\) to find an unclosed
{or(above the error
Code examples
Missing semicolon after a struct
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
- Position — Is the mistake on the line before the reported one?
- Braces — Do every
{and(have a partner? - 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:
Similar errors
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 15 Oct 2026