Ad Space — Top Banner

C2143

Visual C++ Programming Language

Severity: Minor

What Does This Error Mean?

C2143 means the compiler found a token it did not expect — most often because the previous statement is missing a semicolon. The error message names the unexpected token: C2143: syntax error: missing ';' before 'identifier'. Look at the line BEFORE the one the error points to — the missing semicolon is almost always there.

Affected Models

  • Visual Studio 2015–2022
  • MSVC v14.x / v17.x

Common Causes

  • Missing semicolon at the end of the previous statement
  • Missing semicolon after a class or struct definition closing brace
  • An incomplete expression — operator without a right operand, for example
  • A macro that expands to something syntactically incomplete
  • A typo that turns a valid token into an unexpected one

How to Fix It

  1. Look at the line reported in the error and then look at the line immediately above it. Add a missing semicolon at the end of that line.

    C2143 is almost always a missing semicolon on the line before the reported location. The compiler only realises something is wrong when it hits the next unexpected token.

  2. Check class and struct definitions — they must end with a semicolon after the closing brace.

    struct Point { int x; int y; } is missing the final semicolon. This mistake causes a cascade of C2143 errors on the lines immediately following the definition.

  3. If the error says 'missing ; before type' on an otherwise correct line, look for a missing semicolon at the end of the previous function or variable declaration.

    The compiler treats the next line as a continuation of the previous broken statement, so the error appears displaced from the actual mistake.

Frequently Asked Questions

I see C2143 on dozens of lines — where do I start?

Fix the first C2143 in the file (the one with the lowest line number) and recompile. A single missing semicolon — especially after a class definition — causes the rest of the file to fail, generating dozens of cascading errors from one root cause.

Can a missing #include cause C2143?

Indirectly, yes. If a type used in a declaration is unknown (due to a missing header), the compiler may misparse the declaration and report C2143. Fix any C2065 undeclared-identifier errors first — they often reveal the missing #include that causes the C2143.