This documentation is archived and is not being maintained.

Compiler Error C2143

Error Message

syntax error : missing 'token1' before 'token2'

The compiler expected a specific token (a language element other than white space) and found another token instead. C2143 can occur in different situations.

See Knowledge Base article Q241706 for information on this error when using a function-try block.

Check the C++ Language Reference to determine where code is syntactically incorrect. Because the compiler may report this error after the line that causes the problem, check the few lines of code that precede the error.

When using /clr and a using directive has a syntax error:

// C2143a.cpp
// compile with: /clr /c
using namespace System.Reflection;   // C2143
using namespace System::Reflection;

When attempting to compile a source code file using CLR syntax without using /clr:

// C2143b.cpp
ref struct A {   // C2143 error compile with /clr
   void Test() {}

int main() {
   A a;

The first non-whitespace character following an if statement should be a left parenthesis. The compiler cannot translate anything else:

// C2143c.cpp
int main() {
   int j = 0;

   // OK
   if (j < 25)

   if (j < 25)   // C2143

Missing closing brace, parenthesis, or semicolon on the line where the error is detected or a few lines above:

// C2143d.cpp
// compile with: /c
class X {
   int member1;
   int member2   // C2143
} x;

Invalid tag in a class declaration:

// C2143e.cpp
class X {
   int member;
} x;

class + {};   // C2143 + is an invalid tag name
class ValidName {};   // OK

A label not attached to a statement. If you must place a label by itself (for example, at the end of a compound statement), attach it to a null statement:

// C2143f.cpp
// compile with: /c
void func1() {
   // OK

   end2:   // C2143

An unqualified call is made to a type in the Standard C++ Library:

// C2143g.cpp
// compile with: /EHsc /c
#include <vector>
static vector<char> bad;   // C2143
static std::vector<char> good;   // OK

Missing typename keyword:

// C2143h.cpp
template <typename T>
struct X {
   struct Y {
      int i;
   Y memFunc();
template <typename T>
X<T>::Y X<T>::memFunc() {   // C2143
// try the following line instead
// typename X<T>::Y X<T>::memFunc() {
   return Y();

Attempting to define an explicit instantiation:

// C2143i.cpp
// compile with: /EHsc /c
// template definition
template <class T>
void PrintType(T i, T j) {}

template void PrintType(float i, float j){}   // C2143
template void PrintType(float i, float j);   // OK

C2143 can also occur due to the way the compiler handles undefined types in a constructor's parameter list. If the compiler encounters an undefined (misspelled?) type, it assumes the constructor is an expression, and issues C2143. To resolve, only use defined types in a constructor parameter list. The following sample generates C20143:

// C2143j.cpp
// compile with: /c
class DataReceived {};
class DataSent {};

struct MyDataController {
   MyDataController(DataSent* u, DataRecieved* j) {}   // C2143
   // try the following line instead
   // MyDataController(DataSent* u, DataReceived* j) {}   // OK