Ad Space — Top Banner

C2059

Visual C++ Programming Language

Severity: Minor

What Does This Error Mean?

C2059 means the compiler found a token — a word, symbol, or keyword — where it did not expect one. The message names the token: C2059: syntax error: ')' or C2059: syntax error: 'return'. Mismatched brackets, a stray semicolon, or a macro that expands to invalid syntax are the most common causes.

Affected Models

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

Common Causes

  • Mismatched parentheses, braces, or brackets — an extra or missing bracket earlier in the file
  • A macro that expands to something syntactically broken at the point of use
  • A stray semicolon inside a class definition where a member declaration was expected
  • Using a C++ keyword (such as 'class' or 'new') as an identifier name
  • Missing comma between items in a function parameter list or initialiser list

How to Fix It

  1. Look at the line reported and the lines immediately around it for an obvious typo: an extra brace, a misplaced semicolon, or a missing comma.

    C2059 is very often a one-character mistake — an extra ), a missing (, or a stray ;.

  2. If a macro name appears in the error, expand the macro manually (or use Edit > Find to see its definition) and check whether its expansion is syntactically valid at the point it is used.

    Macros that work in one context can produce invalid syntax when used in another. Right-click the macro name in Visual Studio and choose Go to Definition to see its expansion.

  3. Use Visual Studio's brace matching (click next to a brace and press Ctrl+]) to verify that all opening brackets have matching closing brackets.

    An unmatched brace from many lines earlier can cause a C2059 far down in the file. The Error List may show the wrong line — the actual mistake is wherever the bracket count went off balance.

  4. Check for reserved keywords used as identifiers. Words like 'class', 'new', 'delete', 'template', and 'namespace' cannot be used as variable or function names.

    If you are porting code from C or another language, some names that were valid there are reserved in C++.

Frequently Asked Questions

C2059 points to the very end of my file — what does that mean?

An unmatched opening brace — { without a closing } — causes the compiler to read past the end of the file looking for the closing brace. C2059 then fires at the end-of-file position. Count your opening and closing braces, or use the brace-matching feature in Visual Studio.

Can a missing #include header cause C2059?

Yes — if a type used in a function signature is unknown because its header is missing, the compiler may misparse the signature and report C2059. Fix C1083 (missing header) and C2065 (undeclared identifier) errors first.