E2040
C++ Builder Programming Language
Severity: MinorWhat Does This Error Mean?
E2040 means the compiler was parsing a declaration and found a token it did not expect before the declaration finished. The most common cause is a missing semicolon at the end of a class definition, struct definition, or variable declaration. The error message points to the line where the compiler gave up — check the line before it for the syntax mistake.
Affected Models
- C++ Builder 10.x (Alexandria)
- C++ Builder 11 (Sydney)
- C++ Builder 12 (Athens)
- RAD Studio 11 and 12
Common Causes
- Missing semicolon at the end of a class, struct, or union definition
- Extra comma or semicolon inside a class member declaration list
- A __declspec or __property declaration with incorrect syntax
- A typo turning a valid declarator into something the compiler cannot parse
- Using a C++ keyword as an identifier name in a declaration
How to Fix It
-
Look at the line the error points to and the line immediately before it. Add a missing semicolon at the end of the previous declaration.
Like C2143 in MSVC, E2040 fires at the next token after the incomplete declaration — the actual mistake is usually on the previous line.
-
Check class and struct definitions for a missing semicolon after the closing brace.
class TMyClass { ... } is missing the semicolon. It must be: class TMyClass { ... }; This is a very common mistake and causes many cascade errors in the lines that follow.
-
If the declaration uses C++ Builder-specific extensions such as __property or __published, verify the syntax matches the RAD Studio documentation.
__property declarations require the read and write specifiers in a specific order. An incorrect __property declaration reliably triggers E2040.
Frequently Asked Questions
Is E2040 the same as the MSVC C2143 error?
Very similar — both mean a declaration was not correctly terminated, usually due to a missing semicolon. The root causes and fixes are nearly identical across both compilers.
E2040 appears in a header I did not write — what should I do?
If the error is in a VCL or third-party header, the issue is almost never in that header itself — something you wrote (a missing semicolon or bad macro) is corrupting the parser state before it reaches that header. Fix errors in your own code first.