Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2059: syntax error : 'constant'

I've got a piece of code that's automatically generated that compiles on Linux but not on Windows using Visual Studio 2008 Express. The issue I'm having is that I don't understand the compiler error. I don't think I can post the exact code, so here's a sanitized version of it...

Error is reported for the line declaring the static const DELETE. Note: The compiler error doesn't show up when this file is compiled - it builds into a library successfully, but shows up in a second project that includes the header (indirectly). I believe there are at least one or two other projects that include it indirectly in the solution - they have no issues compiling.

File_A.h:

enum LONG_TYPE_NAME {
  ENUM_NAME_PREFIX_ADD = 0,
  ENUM_NAME_PREFIX_CHANGE = 1,
  ENUM_NAME_PREFIX_DELETE = 2,
  ENUM_NAME_PREFIX_SOMETHINGELSE = 3,
};
//Lots of code here
class FOO : public ::LIBRARY_NAME {
 public:
  //Some stuff
  private:
  //Some stuff
  public:
  //Some more stuff

  typedef LONG_TYPE_NAME SHORT_NAME;
  static const SHORT_NAME ADD = ENUM_NAME_PREFIX_ADD;
  static const SHORT_NAME CHANGE = ENUM_NAME_PREFIX_CHANGE; 

  /* compiler error for the following line only*/
  static const SHORT_NAME DELETE = ENUM_NAME_PREFIX_DELETE; 
  static const SHORT_NAME SOMETHINGELSE = ENUM_NAME_PREFIX_SOMETHINGELSE; 

  //More stuff
};

The constant itself only shows up in one place (when I search through the project for the term DELETE):

File_A.cc:

#ifndef _MSC_VER
const LONG_TYPE_NAME FOO::ADD;
const LONG_TYPE_NAME FOO::CHANGE;
const LONG_TYPE_NAME FOO::DELETE;
//More stuff
#endif  // _MSC_VER

The error reported is error C2059: syntax error : 'constant' (followed by error C2258: illegal pure syntax, must be '= 0' and error C4430: missing type specifier - int assumed. Note: C++ does not support default-int which I assume are not relevant), but not when the files above are being compiled.

The files are compiled to a library which is statically linked to by another project (C++) - this is the one that's generating the error (as well as in a second .cpp file that does something similar). It still shows up when I comment out all the code, so I assume it has something to do with header inclusions.

Commenting out the line generating the error makes the build work on Windows (and fail on Linux, but I assume that commenting out its counterpart in the ifndef should fix that), but I really want to know why the compiler is failing for that particular line and what the error actually means. Also, it's probably better not to modify code that's been automatically generated.

EDIT: Splitting up the terms into individual lines makes the compiler point to the DELETE line. Maybe there's a macro automatically defined with the name DELETE somewhere?

EDIT 2: Cleaned up the heading section a bit to clear up some possible misconceptions. Incidentally, renaming the DELETE variable also clears out the error.

EDIT 3: Clearly I need to learn more about VS - /P generates the preprocessed file without producing the object file, so the build will of course fail without generating compilation errors. Also, it does look like there is a macro somewhere, which defines DELETE as (0x00010000L).

like image 382
Nan L Avatar asked May 09 '12 14:05

Nan L


1 Answers

There's definitely a macro DELETE defined somewhere.

like image 125
AnT Avatar answered Oct 08 '22 04:10

AnT